예제 #1
0
    def test_override_variables_binds(self):
        map_list = [
            {"a": 1},
            {"b": 2}
        ]
        override_mapping = {"a": 3, "c": 4}
        new_dict = utils.override_mapping_list(map_list, override_mapping)
        self.assertEqual(3, new_dict["a"])
        self.assertEqual(4, new_dict["c"])

        map_list = OrderedDict(
            {
                "a": 1,
                "b": 2
            }
        )
        override_mapping = {"a": 3, "c": 4}
        new_dict = utils.override_mapping_list(map_list, override_mapping)
        self.assertEqual(3, new_dict["a"])
        self.assertEqual(4, new_dict["c"])

        map_list = "invalid"
        override_mapping = {"a": 3, "c": 4}
        with self.assertRaises(exceptions.ParamsError):
            utils.override_mapping_list(map_list, override_mapping)
예제 #2
0
    def parse_tests(self, testcases, variables_mapping=None):
        """ parse testcases configs, including variables/parameters/name/request.

        Args:
            testcases (list): testcase list, with config unparsed.
            variables_mapping (dict): if variables_mapping is specified, it will override variables in config block.

        Returns:
            list: parsed testcases list, with config variables/parameters/name/request parsed.

        """
        variables_mapping = variables_mapping or {}

        parsed_testcases_list = []
        for testcase in testcases:

            config = testcase.setdefault("config", {})

            # parse config parameters
            config_parameters = config.pop("parameters", [])
            cartesian_product_parameters_list = parser.parse_parameters(
                config_parameters,
                self.project_mapping["debugtalk"]["variables"],
                self.project_mapping["debugtalk"]["functions"]) or [{}]

            for parameter_mapping in cartesian_product_parameters_list:
                # parse config variables
                raw_config_variables = config.get("variables", [])
                parsed_config_variables = parser.parse_data(
                    raw_config_variables,
                    self.project_mapping["debugtalk"]["variables"],
                    self.project_mapping["debugtalk"]["functions"])

                # priority: passed in > debugtalk.py > parameters > variables
                # override variables mapping with parameters mapping
                config_variables = utils.override_mapping_list(
                    parsed_config_variables, parameter_mapping)
                # merge debugtalk.py module variables
                config_variables.update(
                    self.project_mapping["debugtalk"]["variables"])
                # override variables mapping with passed in variables_mapping
                config_variables = utils.override_mapping_list(
                    config_variables, variables_mapping)

                testcase["config"]["variables"] = config_variables

                # parse config name
                testcase["config"]["name"] = parser.parse_data(
                    testcase["config"].get("name", ""), config_variables,
                    self.project_mapping["debugtalk"]["functions"])

                # parse config request
                testcase["config"]["request"] = parser.parse_data(
                    testcase["config"].get("request", {}), config_variables,
                    self.project_mapping["debugtalk"]["functions"])

                # put loaded project functions to config
                testcase["config"]["functions"] = self.project_mapping[
                    "debugtalk"]["functions"]
                parsed_testcases_list.append(testcase)

        return parsed_testcases_list
예제 #3
0
    def parse_tests(self, testcases, variables_mapping=None):
        """ parse testcases configs, including variables/parameters/name/request.

        Args:
            testcases (list): testcase list, with config unparsed.
            variables_mapping (dict): if variables_mapping is specified, it will override variables in config block.

        Returns:
            list: parsed testcases list, with config variables/parameters/name/request parsed.

        """
        self.exception_stage = "parse tests"
        variables_mapping = variables_mapping or {}

        parsed_testcases_list = []
        for testcase in testcases:
            # parse config parameters
            config_parameters = testcase.setdefault("config",
                                                    {}).pop("parameters", [])

            cartesian_product_parameters_list = parser.parse_parameters(
                config_parameters,
                self.project_mapping["debugtalk"]["variables"],
                self.project_mapping["debugtalk"]["functions"]) or [{}]

            for parameter_mapping in cartesian_product_parameters_list:
                testcase_dict = testcase
                config = testcase_dict.setdefault("config", {})

                testcase_dict["config"]["functions"] = {}

                # imported_module = importlib.reload(importlib.import_module('func_list.build_in'))
                # testcase_dict["config"]["functions"].update(loader.load_python_module(imported_module)["functions"])

                if config.get('import_module_functions'):
                    for f in config.get('import_module_functions'):
                        imported_module = importlib.reload(
                            importlib.import_module(f))
                        debugtalk_module = loader.load_python_module(
                            imported_module)
                        testcase_dict["config"]["functions"].update(
                            debugtalk_module["functions"])
                testcase_dict["config"]["functions"].update(
                    self.project_mapping["debugtalk"]["functions"])
                # self.project_mapping["debugtalk"]["functions"].update(debugtalk_module["functions"])
                raw_config_variables = config.get("variables", [])
                parsed_config_variables = parser.parse_data(
                    raw_config_variables,
                    self.project_mapping["debugtalk"]["variables"],
                    testcase_dict["config"]["functions"])

                # priority: passed in > debugtalk.py > parameters > variables
                # override variables mapping with parameters mapping
                config_variables = utils.override_mapping_list(
                    parsed_config_variables, parameter_mapping)
                # merge debugtalk.py module variables
                config_variables.update(
                    self.project_mapping["debugtalk"]["variables"])
                # override variables mapping with passed in variables_mapping
                config_variables = utils.override_mapping_list(
                    config_variables, variables_mapping)

                testcase_dict["config"]["variables"] = config_variables

                # parse config name
                testcase_dict["config"]["name"] = parser.parse_data(
                    testcase_dict["config"].get("name", ""), config_variables,
                    self.project_mapping["debugtalk"]["functions"])

                # parse config request
                testcase_dict["config"]["request"] = parser.parse_data(
                    testcase_dict["config"].get("request",
                                                {}), config_variables,
                    self.project_mapping["debugtalk"]["functions"])
                # put loaded project functions to config
                # testcase_dict["config"]["functions"] = self.project_mapping["debugtalk"]["functions"]
                parsed_testcases_list.append(testcase_dict)
        return parsed_testcases_list
예제 #4
0
def parse_tests(testcases, variables_mapping=None):
    """ parse testcases configs, including variables/parameters/name/request.

    Args:
        testcases (list): testcase list, with config unparsed.
            [
                {   # testcase data structure
                    "config": {
                        "name": "desc1",
                        "path": "testcase1_path",
                        "variables": [],         # optional
                        "request": {}            # optional
                        "refs": {
                            "debugtalk": {
                                "variables": {},
                                "functions": {}
                            },
                            "env": {},
                            "def-api": {},
                            "def-testcase": {}
                        }
                    },
                    "teststeps": [
                        # teststep data structure
                        {
                            'name': 'test step desc2',
                            'variables': [],    # optional
                            'extract': [],      # optional
                            'validate': [],
                            'request': {},
                            'function_meta': {}
                        },
                        teststep2   # another teststep dict
                    ]
                },
                testcase_dict_2     # another testcase dict
            ]
        variables_mapping (dict): if variables_mapping is specified, it will override variables in config block.

    Returns:
        list: parsed testcases list, with config variables/parameters/name/request parsed.

    """
    variables_mapping = variables_mapping or {}
    parsed_testcases_list = []

    for testcase in testcases:
        testcase_config = testcase.setdefault("config", {})
        project_mapping = testcase_config.pop(
            "refs",
            {
                "debugtalk": {
                    "variables": {},
                    "functions": {}
                },
                "env": {},
                "def-api": {},
                "def-testcase": {}
            }
        )

        # parse config parameters
        config_parameters = testcase_config.pop("parameters", [])
        cartesian_product_parameters_list = parse_parameters(
            config_parameters,
            project_mapping["debugtalk"]["variables"],
            project_mapping["debugtalk"]["functions"]
        ) or [{}]

        for parameter_mapping in cartesian_product_parameters_list:
            testcase_dict = utils.deepcopy_dict(testcase)
            config = testcase_dict.get("config")

            # parse config variables
            raw_config_variables = config.get("variables", [])
            parsed_config_variables = parse_data(
                raw_config_variables,
                project_mapping["debugtalk"]["variables"],
                project_mapping["debugtalk"]["functions"]
            )

            # priority: passed in > debugtalk.py > parameters > variables
            # override variables mapping with parameters mapping
            config_variables = utils.override_mapping_list(
                parsed_config_variables, parameter_mapping)
            # merge debugtalk.py module variables
            config_variables.update(project_mapping["debugtalk"]["variables"])
            # override variables mapping with passed in variables_mapping
            config_variables = utils.override_mapping_list(
                config_variables, variables_mapping)

            testcase_dict["config"]["variables"] = config_variables

            # parse config name
            testcase_dict["config"]["name"] = parse_data(
                testcase_dict["config"].get("name", ""),
                config_variables,
                project_mapping["debugtalk"]["functions"]
            )

            # parse config request
            testcase_dict["config"]["request"] = parse_data(
                testcase_dict["config"].get("request", {}),
                config_variables,
                project_mapping["debugtalk"]["functions"]
            )

            # put loaded project functions to config
            testcase_dict["config"]["functions"] = project_mapping["debugtalk"]["functions"]
            parsed_testcases_list.append(testcase_dict)

    return parsed_testcases_list