Ejemplo n.º 1
0
    def bind_variables(self, variable_binds, level="testcase"):
        """ bind variables to testset context or current testcase context.
            variables in testset context can be used in all testcases of current test suite.

        @param (list or OrderDict) variable_binds, variable can be value or custom function.
            if value is function, it will be called and bind result to variable.
        e.g.
            OrderDict({
                "TOKEN": "debugtalk",
                "random": "${gen_random_string(5)}",
                "json": {'name': 'user', 'password': '******'},
                "md5": "${gen_md5($TOKEN, $json, $random)}"
            })
        """
        if isinstance(variable_binds, list):
            variable_binds = utils.convert_to_order_dict(variable_binds)

        for variable_name, value in variable_binds.items():
            variable_evale_value = self.testcase_parser.parse_content_with_bindings(
                value)

            if level == "testset":
                self.testset_shared_variables_mapping[
                    variable_name] = variable_evale_value

            self.testcase_variables_mapping[
                variable_name] = variable_evale_value
            self.testcase_parser.bind_variables(
                self.testcase_variables_mapping)
Ejemplo n.º 2
0
 def test_update_ordered_dict(self):
     map_list = [{"a": 1}, {"b": 2}]
     ordered_dict = utils.convert_to_order_dict(map_list)
     override_mapping = {"a": 3, "c": 4}
     new_dict = utils.update_ordered_dict(ordered_dict, override_mapping)
     self.assertEqual(3, new_dict["a"])
     self.assertEqual(4, new_dict["c"])
Ejemplo n.º 3
0
    def extract_response(self, extractors):
        """ extract content from requests.Response
        @param (list) extractors
            [
                {"resp_status_code": "status_code"},
                {"resp_headers_content_type": "headers.content-type"},
                {"resp_content": "content"},
                {"resp_content_person_first_name": "content.person.name.first_name"}
            ]
        @return (OrderDict) variable binds ordered dict
        """
        extracted_variables_mapping = OrderedDict()
        extract_binds_order_dict = utils.convert_to_order_dict(extractors)

        for key, field in extract_binds_order_dict.items():
            if not isinstance(field, utils.string_type):
                raise exception.ParamsError("invalid extractors in testcase!")

            extracted_variables_mapping[key] = self.extract_field(field)

        return extracted_variables_mapping
Ejemplo n.º 4
0
 def test_convert_to_order_dict(self):
     map_list = [{"a": 1}, {"b": 2}]
     ordered_dict = utils.convert_to_order_dict(map_list)
     self.assertIsInstance(ordered_dict, dict)
     self.assertIn("a", ordered_dict)