コード例 #1
0
    def _update_yaml(
            yaml: YamlInputFile, test_suite: str, test_case: str,
            element: str, value: typing.Any) -> None:
        """
        Provided a listed YAML structure, the testsuite and testcase, the
        attribute name to update, and the value to update the attribute to,
        find the attribute and update the structure.

        Args:
            yaml (ReferentialYAML): YAML Structure
            test_suite (str): Test suite name
            test_case (str): Test case name
            element (str): Name of test case attribute to update
            value (Any): Value or structure to update attribute to

        Returns:
            None

        """
        tc_data = ReferentialYAML.get_referenced_test_data(
            yaml_input=yaml, testsuite=test_suite, testcase=test_case)

        if element not in tc_data:
            logging.warn(f"Unable to find requested element: "
                         f"'{element}' in yaml_file")
            logging.warn(f"Test case found: {', '.join(tc_data.keys())}")
            logging.warn(f"Adding attribute '{element}' to structure.")
            logging.info(f"Inserting value: {value}")
        else:
            logging.info(f"ELEMENT: {element}")
            logging.info(f"UPDATED VALUE: {value}")

        tc_data[element] = value

        logging.info(f"Updated YAML: {pprint.pformat(yaml)}")
コード例 #2
0
    def _get_testcase_ids(
            yaml_data: typing.Union[ReferentialYAML, YamlInputFile],
            test_suite: str, test_case: str) -> list:

        """
        Get the list of step ids within test_suite:test_case structure
        (yaml data)

        Args:
            yaml_data (YamlInputFile): YAML data structure
            test_suite (str): Name of test suite in data
            test_case (str): Name of test case in data

        Returns:
            (list) List of ids

        """
        # Get the test case definition
        tc_data = ReferentialYAML.get_referenced_test_data(
            yaml_input=yaml_data, testsuite=test_suite, testcase=test_case)

        logging.debug(f"TEST CASE DATA:\n{pprint.pformat(tc_data)}")

        # Get the step definitions from the test case definition
        steps = tc_data[YAMLConsts.STEPS]

        # Get the ids of the steps (maintained in order)
        step_ids = [str(list(x.values())[0][YAMLConsts.ID]) for x in steps]
        return step_ids
コード例 #3
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
コード例 #4
0
    def _get_testcase_steps(
            yaml_data: YamlInputFile, test_suite: str, test_case: str) -> list:

        """
        Get the list of steps within test_suite:test_case structure (yaml data)

        Args:
            yaml_data (YamlInputFile): YAML data structure
            test_suite (str): Name of test suite in data
            test_case (str): Name of test case in data

        Returns:
            (list) List of steps

        """
        # Get the test case definition
        tc_data = ReferentialYAML.get_referenced_test_data(
            yaml_input=yaml_data, testsuite=test_suite, testcase=test_case)

        logging.debug(f"TEST CASE DATA:\n{pprint.pformat(tc_data)}")

        # Get the step definitions from the test case definition
        steps = tc_data.get(YAMLConsts.STEPS, {})

        # Get the names of the steps (maintained in order)
        step_names = [list(x.keys())[0] for x in steps]
        return step_names
コード例 #5
0
    def _test_modify_steps(
            self, filename: str, testsuite: str, testcase: str,
            updated_step_data: list) -> typing.Tuple[dict, dict]:
        """
        Get the ReferentialYAML file, and update the specified testsuite &
        testcase with the specified modifications

        Args:
            filename (str): Name of the YAML file to read
            testsuite (str): Test suite to update
            testcase (str): Test case to update
            updated_step_data (List): List of dictionaries of updated step data

        Returns:
            Tuple of 2 dictionaries (expected & actual test case definitions)

        """
        element = YAMLConsts.MOD_STEPS
        ref_yaml_obj = self._read_and_update_source_yaml_file(
            filename=filename, testsuite=testsuite, testcase=testcase,
            element=element, value=updated_step_data)

        # EXPECTED: Get the original step definition, make a copy, and combine
        # the updated data for the step
        orig_tc_data = ReferentialYAML.get_referenced_test_data(
            yaml_input=ref_yaml_obj, testsuite=self.TEST_SUITE,
            testcase=self.TEST_CASE)
        orig_tc_data = copy.deepcopy(orig_tc_data)

        expected_tc = self._combine_steps(
            original=orig_tc_data, modifications=updated_step_data[0])
        logging.info(f"Expected TC YAML:\n{pprint.pformat(expected_tc)}")

        # MODIFY the requested steps via the actual source code
        ref_yaml_obj.modify_steps()

        # ACTUAL: Get the actual testcase
        actual_tc = ReferentialYAML.get_referenced_test_data(
            yaml_input=ref_yaml_obj, testsuite=self.TEST_SUITE,
            testcase=self.TEST_CASE)
        logging.info(f"Actual TC YAML:\n{pprint.pformat(actual_tc)}")

        return expected_tc, actual_tc