diff --git a/framework/validation/validation.py b/framework/validation/validation.py index c3ef478b..cc781407 100644 --- a/framework/validation/validation.py +++ b/framework/validation/validation.py @@ -75,6 +75,30 @@ def validate_equals_with_retry( raise TimeoutError(f"Timeout performing validation - {validation_description}") +def validate_not_equals(observed_value: Any, expected_value: Any, validation_description: str) -> None: + """ + This function will validate if the observed value does not match the expected value with associated logging. + + Args: + observed_value (Any): Value that we see on the system. + expected_value (Any): Value that is not expected and against which we are asserting. + validation_description (str): Description of this validation for logging purposes. + + Returns: None + + Raises: + Exception: raised when validate fails + + """ + if observed_value != expected_value: + get_logger().log_info(f"Validation Successful - {validation_description}") + else: + get_logger().log_error(f"Validation Failed - {validation_description}") + get_logger().log_error(f"Expected: {expected_value}") + get_logger().log_error(f"Observed: {observed_value}") + raise Exception("Validation Failed") + + def validate_str_contains(observed_value: str, expected_value: str, validation_description: str) -> None: """ This function will validate if the observed value contains the expected value. diff --git a/unit_tests/framework/validation/validaton_test.py b/unit_tests/framework/validation/validaton_test.py index f0f8f45e..3486912c 100644 --- a/unit_tests/framework/validation/validaton_test.py +++ b/unit_tests/framework/validation/validaton_test.py @@ -2,7 +2,7 @@ from config.configuration_file_locations_manager import ( ConfigurationFileLocationsManager, ) from config.configuration_manager import ConfigurationManager -from framework.validation.validation import validate_str_contains +from framework.validation.validation import validate_not_equals, validate_str_contains def test_validate_str_contains(): @@ -25,3 +25,27 @@ def test_validate_str_contains_fails(): assert False, "Validation passed when it should not have" # if test succeeds, we should never get to this line except Exception as e: assert e.__str__() == "Validation Failed", "Validation failed as expected." + + +def test_validate_not_equals_str(): + """ + Tests the validate not equals function with a string + + """ + configuration_locations_manager = ConfigurationFileLocationsManager() + ConfigurationManager.load_configs(configuration_locations_manager) + validate_not_equals("success", "unsuccess", "Test that the words success and unsuccess are not equal") + + +def test_validate_not_equals_list(): + """ + Tests the validate not equals function with a list + + """ + configuration_locations_manager = ConfigurationFileLocationsManager() + ConfigurationManager.load_configs(configuration_locations_manager) + + list1 = ["success", "successful"] + list2 = ["success", "unsuccessful"] + + validate_not_equals(list1, list2, "Test that the lists are not equal")