Esempio n. 1
0
    def test_get_possible_test_cases(self):

        # Test get_possible_test_cases routine in path_yaml.py
        # Test requires specific data file

        # Determine expected results
        test_suite_name = "EXAMPLE_2"
        expected_num_test_cases = 2
        expected_testcase_names = [
            f'test_{x + 1}' for x in range(expected_num_test_cases)
        ]

        # Determine data file path
        data_file = get_data_file(filename=self.SAMPLE_PATH,
                                  test_dir_name=self.TEST_DIR_NAME,
                                  data_dir_name=self.DATA_DIR_NAME)

        # Execute routine
        state_path_obj = StatePathsYaml(data_file)
        test_case_list = state_path_obj.get_possible_test_cases(
            test_suite=test_suite_name)

        logging.info(f"EXPECTED TEST CASES: {expected_testcase_names}")
        logging.info(f"RETURNED TEST CASES: {test_case_list}")

        # Verify right number and names are returned.
        assert_equals(len(test_case_list), expected_num_test_cases)
        for tc_name in test_case_list:
            assert_in(tc_name, expected_testcase_names)
Esempio n. 2
0
    def _test_get_referenced_test_data(
            self, filename: str, testsuite: str, testcase: str) -> dict:
        """
        Call get_referenced_test_data and return results

        Args:
            filename (str): Name of YAML file to read
            testsuite (str): Name of testsuite to retrieve
            testcase (str): Name of testcase to retrieve

        Returns:
            Dict: test case definition that meet the provide parameters

        """
        data_file = get_data_file(
            test_dir_name=self.TESTS_SUBDIR, data_dir_name=self.DATA_SUBDIR,
            filename=filename)

        yaml_obj = YamlInputFile(input_file=data_file)
        ref_yaml_obj = ReferentialYAML(yaml_input=yaml_obj)

        tc_data = ref_yaml_obj.get_referenced_test_data(
            yaml_input=ref_yaml_obj, testsuite=testsuite, testcase=testcase)

        return tc_data
Esempio n. 3
0
    def test_add_referenced_tc_to_ts_where_tc_is_new(self):
        tc_data = {
            YAMLConsts.DESCRIPTION: "Added test",
            YAMLConsts.STEPS: {
                'STEP_A': {},
                'STEP_B': {}
            }
        }
        test_case_name = "NEW_TEST_CASE"

        data_file = get_data_file(
            test_dir_name=self.TESTS_SUBDIR,
            data_dir_name=self.DATA_SUBDIR,
            filename=self.SIMPLE_REF)

        yaml_obj = YamlInputFile(input_file=data_file)
        ref_yaml_obj = ReferentialYAML(yaml_input=yaml_obj)

        ref_yaml_obj.add_referenced_tc_to_ts(
            target_ts=self.TEST_SUITE,
            target_tc=test_case_name,
            tc_data=tc_data)

        updated_tc_yaml = ref_yaml_obj.data[0][self.TEST_SUITE][test_case_name]

        logging.info(f"Data added: {tc_data}")
        logging.info(f"Updated YAML Data: {updated_tc_yaml}")

        assert_equals(tc_data.get(YAMLConsts.STEPS, {}),
                      updated_tc_yaml.get(YAMLConsts.STEPS, {}))
Esempio n. 4
0
    def test_get_test_suites(self) -> NoReturn:
        # """
        #
        # Test suite names in yaml file match number and definition
        #
        # Returns:
        #     None
        # """

        # Determine expected data
        num_test_suites = 2
        expected_test_suite_names = [
            f"EXAMPLE_{x + 1}" for x in range(num_test_suites)
        ]

        # Determine data file path
        data_file = get_data_file(filename=self.SAMPLE_PATH,
                                  test_dir_name=self.TEST_DIR_NAME,
                                  data_dir_name=self.DATA_DIR_NAME)

        # Execute routine
        state_path_obj = StatePathsYaml(data_file)
        test_suites = state_path_obj.get_test_suites()

        logging.info(f"EXPECTED TEST SUITES: {expected_test_suite_names}")
        logging.info(f"RETURNED TEST SUITES: {test_suites}")

        # Verify right number and names are returned.
        assert_equals(len(test_suites), num_test_suites)
        for name in test_suites:
            assert_in(name, expected_test_suite_names)
Esempio n. 5
0
    def test_get_traversal_path_with_test_case_def(self):
        # Determine expected results
        test_suite_name = 'EXAMPLE_1'

        num_test_cases = 2
        test_case_name = 'test_{num}'.format(
            num=choice([x + 1 for x in range(num_test_cases)]))

        num_steps_in_test_case = 4
        step_names = [f"STEP_{x + 1}" for x in range(num_steps_in_test_case)]

        # Determine data file path
        data_file = get_data_file(filename=self.SAMPLE_PATH,
                                  test_dir_name=self.TEST_DIR_NAME,
                                  data_dir_name=self.DATA_DIR_NAME)

        # Execute routine
        state_path_obj = StatePathsYaml(data_file)
        tc_def = state_path_obj.build_test_case(test_suite=test_suite_name,
                                                test_name=test_case_name)
        traversal_path = state_path_obj.get_traversal_path(
            test_case_def=tc_def)

        assert_equals(len(traversal_path), num_steps_in_test_case)
        for trigger in traversal_path:
            assert_in(trigger, step_names)
Esempio n. 6
0
    def test_list_test_info_works_with_dne_test_suite(self):
        # Determine data file path
        data_file = get_data_file(filename=self.SAMPLE_PATH,
                                  test_dir_name=self.TEST_DIR_NAME,
                                  data_dir_name=self.DATA_DIR_NAME)

        # Execute routine
        state_path_obj = StatePathsYaml(data_file)
        state_path_obj.list_test_info(test_suite='imaginary')
Esempio n. 7
0
    def test_show_file(self):
        # Determine data file path
        data_file = get_data_file(filename=self.SAMPLE_PATH,
                                  test_dir_name=self.TEST_DIR_NAME,
                                  data_dir_name=self.DATA_DIR_NAME)

        # Execute routine
        state_path_obj = StatePathsYaml(data_file)
        state_path_obj.show_file()
Esempio n. 8
0
    def _get_traversal_with_invalid_params(self, ts, tc):
        # Determine data file path
        data_file = get_data_file(filename=self.SAMPLE_PATH,
                                  test_dir_name=self.TEST_DIR_NAME,
                                  data_dir_name=self.DATA_DIR_NAME)

        # Execute routine
        state_path_obj = StatePathsYaml(data_file)
        traversal_path = state_path_obj.get_traversal_path(test_suite=ts,
                                                           test_case=tc)

        assert_equals(len(traversal_path), 0)
Esempio n. 9
0
    def _read_and_update_source_yaml_file(
            self, filename: str, testsuite: str, testcase: str,
            element: str, value: typing.Any,
            ref_yaml: ReferentialYAML = None) -> ReferentialYAML:
        """
        Read the specified file, and update the corresponding testsuite/testcase
        element with the provided value.

        Args:
            filename (str): Name of the YAML file
            testsuite (str): Testsuite to update
            testcase (str): Testcase to update
            element (str): Testcase element (dict key) to update
            value (any): Value to update the testcase element
            ref_yaml (ReferentialYAML): Populated Referential Yaml File Obj

        Returns:
            Updated ReferentialYAML Object

        """

        if ref_yaml is None:

            # Read YAML File
            data_file = get_data_file(
                test_dir_name=self.TESTS_SUBDIR,
                data_dir_name=self.DATA_SUBDIR,
                filename=filename)
            yaml_obj = YamlInputFile(input_file=data_file)

        else:
            yaml_obj = ref_yaml.yaml
            ref_yaml_obj = ref_yaml

        # Insert the MOD_STEP data to the YAML structure
        self._update_yaml(
            yaml=yaml_obj, test_suite=testsuite, test_case=testcase,
            element=element, value=value)

        # Build reference YAML object and add the data from
        # the primary reference
        if ref_yaml is None:
            ref_yaml_obj = ReferentialYAML(yaml_input=yaml_obj)
            assert_true(ref_yaml_obj.check_if_file_references_another_file())

        ref_yaml_obj._add_referenced_paths()
        logging.info(f"Updated YAML:\n{pprint.pformat(ref_yaml_obj.data)}")

        return ref_yaml_obj
Esempio n. 10
0
    def _get_path_validation_fail_path(self, ts: str, tc: str) -> NoReturn:

        # Determine data file path
        data_file = get_data_file(filename=self.SAMPLE_PATH,
                                  test_dir_name=self.TEST_DIR_NAME,
                                  data_dir_name=self.DATA_DIR_NAME)

        # Execute routine
        state_path_obj = StatePathsYaml(data_file)
        expectations = state_path_obj.get_path_validation_expectations(
            test_suite=ts, test_case=tc)

        # Verify expectations is a non-empty list
        assert_true(isinstance(expectations, list))
        assert_equals(expectations, [])
Esempio n. 11
0
    def test_build_test_case_without_params(self):
        # Determine expected results
        test_suite_name = None
        test_case_name = None

        # Determine data file path
        data_file = get_data_file(filename=self.SAMPLE_PATH,
                                  test_dir_name=self.TEST_DIR_NAME,
                                  data_dir_name=self.DATA_DIR_NAME)

        # Execute routine
        state_path_obj = StatePathsYaml(data_file)
        tc_def = state_path_obj.build_test_case(test_suite=test_suite_name,
                                                test_name=test_case_name)

        assert_equals(len(tc_def), 0)
Esempio n. 12
0
    def test_build_test_case_with_invalid_info(self, mock_inv_resp: str):

        test_suite_name = "EXAMPLE_1"
        test_case_name = "test_1"

        # Determine data file path
        data_file = get_data_file(filename=self.SAMPLE_PATH,
                                  test_dir_name=self.TEST_DIR_NAME,
                                  data_dir_name=self.DATA_DIR_NAME)

        # Execute routine (with mocked response in build_test_case)
        state_path_obj = StatePathsYaml(data_file)
        tc_def = state_path_obj.build_test_case(test_suite=test_suite_name,
                                                test_name=test_case_name)

        assert_equals(tc_def, [])
Esempio n. 13
0
    def test_get_path_validation_expectations_with_test_def(self):
        # Test the StatePathYaml.get_test_validation_expectations() with a
        # valid testcase and testsuite

        expected_test_suite = 'EXAMPLE_1'
        expected_test_case = 'test_1'
        num_expectations = 2
        expectation_ids = [
            f"expectation_{x + 1}" for x in range(num_expectations)
        ]

        # Determine data file path
        data_file = get_data_file(filename=self.SAMPLE_PATH,
                                  test_dir_name=self.TEST_DIR_NAME,
                                  data_dir_name=self.DATA_DIR_NAME)

        # Execute routine
        state_path_obj = StatePathsYaml(data_file)
        test_def = state_path_obj.build_test_case(
            test_suite=expected_test_suite, test_name=expected_test_case)
        expectations = state_path_obj.get_path_validation_expectations(
            test_case_def=test_def)

        # Verify expectations is a non-empty list
        assert_true(isinstance(expectations, list))
        assert_not_equals(expectations, [])

        # Verify each entry in the list (dictionary of dictionaries) has the
        # expected keys and the values are the correct data type (bool)
        for step in expectations:
            step_name = list(step.keys())[0]
            logging.info(f"STEP NAME: {step_name}")
            expectation_dict = list(step.values())[0]

            # Verify the keys are correct
            for exp_id in expectation_ids:
                assert_in(
                    exp_id, list(expectation_dict.keys()),
                    f"{step_name}: Expected key ({exp_id}) was not found "
                    f"in the list of defined keys.")

                # Verify the values are booleans
                for key, exp in list(expectation_dict.items()):
                    assert_true(
                        isinstance(exp, bool),
                        f"{step_name}: Expected value {str(exp)} for "
                        f"{key} was not a boolean")
Esempio n. 14
0
    def test_check_if_file_references_empty_string(self):
        data_file = get_data_file(
            test_dir_name=self.TESTS_SUBDIR,
            data_dir_name=self.DATA_SUBDIR,
            filename=self.SIMPLE_REF)

        yaml_obj = YamlInputFile(input_file=data_file)

        self._update_yaml(yaml=yaml_obj,
                          test_suite=self.TEST_SUITE,
                          test_case=self.TEST_CASE,
                          element=SMConsts.REFERENCE,
                          value='')

        ref_yaml_obj = ReferentialYAML(yaml_input=yaml_obj)

        # Verify the reference is found but fails due to being unable to parse
        ref_yaml_obj.check_if_file_references_another_file()
Esempio n. 15
0
    def test_check_if_file_references_another_file_invalid_reference(self):
        data_file = get_data_file(
            test_dir_name=self.TESTS_SUBDIR,
            data_dir_name=self.DATA_SUBDIR,
            filename=self.SIMPLE_REF)

        yaml_obj = YamlInputFile(input_file=data_file)

        illegal_value = (f"{self.BASE_REF_FILE}{ReferentialYAML.DELIMITER}"
                         f"{self.TEST_SUITE}{ReferentialYAML.DELIMITER}")

        self._update_yaml(yaml=yaml_obj,
                          test_suite=self.TEST_SUITE,
                          test_case=self.TEST_CASE,
                          element=SMConsts.REFERENCE,
                          value=illegal_value)

        ref_yaml_obj = ReferentialYAML(yaml_input=yaml_obj)

        # Verify the reference is found but fails due to being unable to parse
        ref_yaml_obj.check_if_file_references_another_file()
Esempio n. 16
0
    def test_build_test_case_with_correct_params(self):
        # Determine expected results
        test_suite_name = "EXAMPLE_1"
        test_case_name = "test_1"
        test_case_steps = 4
        step_names = [f"STEP_{x + 1}" for x in range(test_case_steps)]

        # Determine data file path
        data_file = get_data_file(filename=self.SAMPLE_PATH,
                                  test_dir_name=self.TEST_DIR_NAME,
                                  data_dir_name=self.DATA_DIR_NAME)

        # Execute routine
        state_path_obj = StatePathsYaml(data_file)
        tc_def = state_path_obj.build_test_case(test_suite=test_suite_name,
                                                test_name=test_case_name)
        tc_step_names = [x.trigger for x in tc_def]

        assert_equals(len(tc_def), test_case_steps)
        for step in tc_step_names:
            assert_in(step, step_names)
Esempio n. 17
0
    def test_check_if_file_references_another_valid_file_and_validate_ref(self):

        expected_ref_obj = ReferentialYAML.REFERENCE_DATA(
            target_test_suite=self.TEST_SUITE,
            target_test_case=self.TEST_CASE,
            reference_file=self.BASE_REF_FILE,
            reference_test_suite=self.TEST_SUITE,
            reference_test_case=self.TEST_CASE)

        data_file = get_data_file(
            test_dir_name=self.TESTS_SUBDIR,
            data_dir_name=self.DATA_SUBDIR,
            filename=self.SIMPLE_REF)

        yaml_obj = YamlInputFile(input_file=data_file)
        ref_yaml_obj = ReferentialYAML(yaml_input=yaml_obj)

        # Verify the reference is found
        assert_true(ref_yaml_obj.check_if_file_references_another_file())

        # Verify the reference was parsed correctly
        for ref_obj in ref_yaml_obj.references:
            self._validate_reference_data(expected_ref_obj, ref_obj)
Esempio n. 18
0
    def test_evaluate_yaml_file(self):

        filename = self.SIMPLE_REF
        testsuite = self.TEST_SUITE
        testcase = self.TEST_CASE
        element = YAMLConsts.DEL_STEPS

        added_step_name_1 = 'STEP_1A'
        insert_before_id_1 = '2'
        added_test_case_id_1 = 'ADDED_1'

        added_step_name_2 = 'STEP_2A'
        insert_after_id_2 = 'ADDED_1'
        added_test_case_id_2 = 'ADDED_2'

        add_tc_data = [
            {
                added_step_name_1:
                {
                    YAMLConsts.BEFORE_ID: insert_before_id_1,
                    YAMLConsts.ID: added_test_case_id_1,
                    YAMLConsts.DATA: None,
                    YAMLConsts.EXPECTATIONS: {'test_me': False}
                }
            },
            {
                added_step_name_2:
                {
                    YAMLConsts.AFTER_ID: insert_after_id_2,
                    YAMLConsts.ID: added_test_case_id_2,
                    YAMLConsts.DATA: None,
                    YAMLConsts.EXPECTATIONS: {'test_me': False}
                }
            }
        ]

        modify_tc_data = [
            {
                "STEP_1":
                    {
                        YAMLConsts.ID: 'DNE',
                        YAMLConsts.DATA: {'params': 1, 'value': 7},
                        YAMLConsts.EXPECTATIONS:
                            {
                                "expectations_10": False,
                                "expectations_20": True,
                            }
                    }
            }
        ]

        delete_step_ids = ['3', '4']

        data_file = get_data_file(
            test_dir_name=self.TESTS_SUBDIR, data_dir_name=self.DATA_SUBDIR,
            filename=filename)
        yaml_obj = YamlInputFile(input_file=data_file)
        test_yaml_obj = ReferentialYAML(yaml_input=yaml_obj)
        test_yaml_obj.evaluate_yaml_file()

        ref_yaml_obj = self._read_and_update_source_yaml_file(
            filename=filename, testsuite=testsuite, testcase=testcase,
            element=YAMLConsts.ADD_STEPS, value=add_tc_data)

        ref_yaml_obj = self._read_and_update_source_yaml_file(
            filename=filename, testsuite=testsuite, testcase=testcase,
            element=YAMLConsts.MOD_STEPS, value=modify_tc_data,
            ref_yaml=ref_yaml_obj)

        ref_yaml_obj = self._read_and_update_source_yaml_file(
            filename=filename, testsuite=testsuite, testcase=testcase,
            element=YAMLConsts.DEL_STEPS, value=delete_step_ids,
            ref_yaml=ref_yaml_obj)

        ref_ts = list(ref_yaml_obj.data[0].values())[0]
        ref_tc = list(ref_ts.values())[0]
        del ref_tc[YAMLConsts.ADD_STEPS]
        del ref_tc[YAMLConsts.MOD_STEPS]
        del ref_tc[YAMLConsts.DEL_STEPS]

        assert_equals.__self__.maxDiff = None
        assert_equals(test_yaml_obj.data, ref_yaml_obj.data)