diff --git a/httprunner/context.py b/httprunner/context.py index 59734b29..3c109238 100644 --- a/httprunner/context.py +++ b/httprunner/context.py @@ -51,11 +51,6 @@ class Context(object): function_binds = config_dict.get('function_binds', {}) self.bind_functions(function_binds, level) - # import_module_functions will be deprecated soon - module_items = config_dict.get('import_module_items', []) \ - or config_dict.get('import_module_functions', []) - self.import_module_items(module_items, level) - variables = config_dict.get('variables') \ or config_dict.get('variable_binds', OrderedDict()) self.bind_variables(variables, level) diff --git a/httprunner/runner.py b/httprunner/runner.py index 0174bb9c..312b056d 100644 --- a/httprunner/runner.py +++ b/httprunner/runner.py @@ -38,7 +38,6 @@ class Runner(object): "path": "tests/data/demo_testset_variables.yml", "requires": [], # optional "function_binds": {}, # optional - "import_module_items": [], # optional "variables": [], # optional "request": { "base_url": "http://127.0.0.1:5000", @@ -52,7 +51,6 @@ class Runner(object): "name": "testcase description", "requires": [], # optional "function_binds": {}, # optional - "import_module_items": [], # optional "variables": [], # optional "request": { "url": "/api/get-token", diff --git a/tests/data/demo_binds.yml b/tests/data/demo_binds.yml index 2bfda8a1..6a239c34 100644 --- a/tests/data/demo_binds.yml +++ b/tests/data/demo_binds.yml @@ -25,16 +25,6 @@ bind_lambda_functions_with_import: - data: "{'name': 'user', 'password': '123456'}" - authorization: ${gen_md5($TOKEN, $data, $random)} -bind_module_functions: - function_binds: - import_module_items: - - tests.data.debugtalk - variables: - - TOKEN: debugtalk - - random: ${gen_random_string(5)} - - data: "{'name': 'user', 'password': '123456'}" - - authorization: ${gen_md5($TOKEN, $data, $random)} - builtin_functions: variables: - length: ${len(debugtalk)} diff --git a/tests/data/demo_testset_template_import_functions.yml b/tests/data/demo_testset_template_import_functions.yml index 6d2a0117..ed37ba13 100644 --- a/tests/data/demo_testset_template_import_functions.yml +++ b/tests/data/demo_testset_template_import_functions.yml @@ -1,7 +1,5 @@ - config: name: "create user testsets." - import_module_items: - - tests.debugtalk variables: - user_agent: 'iOS/10.3' - device_sn: ${gen_random_string(15)} diff --git a/tests/test_context.py b/tests/test_context.py index 1d4220f9..8c955b62 100644 --- a/tests/test_context.py +++ b/tests/test_context.py @@ -162,46 +162,38 @@ class VariableBindsUnittest(ApiServerUnittest): self.assertEqual(gen_md5(TOKEN, data, random), authorization) def test_import_module_items(self): - testcase1 = { - "import_module_items": ["tests.debugtalk"], - "variables": [ - {"TOKEN": "debugtalk"}, - {"random": "${gen_random_string(5)}"}, - {"data": '{"name": "user", "password": "123456"}'}, - {"authorization": "${gen_md5($TOKEN, $data, $random)}"} - ] - } - testcase2 = self.testcases["bind_module_functions"] + module_items = ["tests.debugtalk"] + variables = [ + {"TOKEN": "debugtalk"}, + {"random": "${gen_random_string(5)}"}, + {"data": '{"name": "user", "password": "123456"}'}, + {"authorization": "${gen_md5($TOKEN, $data, $random)}"} + ] - for testcase in [testcase1, testcase2]: - module_items = testcase.get('import_module_items', []) - self.context.import_module_items(module_items) + self.context.import_module_items(module_items) + self.context.bind_variables(variables) + context_variables = self.context.testcase_variables_mapping - variables = testcase['variables'] - self.context.bind_variables(variables) - context_variables = self.context.testcase_variables_mapping - - self.assertIn("TOKEN", context_variables) - TOKEN = context_variables["TOKEN"] - self.assertEqual(TOKEN, "debugtalk") - self.assertIn("random", context_variables) - self.assertIsInstance(context_variables["random"], str) - self.assertEqual(len(context_variables["random"]), 5) - random = context_variables["random"] - self.assertIn("data", context_variables) - data = context_variables["data"] - self.assertIn("authorization", context_variables) - self.assertEqual(len(context_variables["authorization"]), 32) - authorization = context_variables["authorization"] - self.assertEqual(gen_md5(TOKEN, data, random), authorization) - self.assertIn("SECRET_KEY", context_variables) - SECRET_KEY = context_variables["SECRET_KEY"] - self.assertEqual(SECRET_KEY, "DebugTalk") + self.assertIn("TOKEN", context_variables) + TOKEN = context_variables["TOKEN"] + self.assertEqual(TOKEN, "debugtalk") + self.assertIn("random", context_variables) + self.assertIsInstance(context_variables["random"], str) + self.assertEqual(len(context_variables["random"]), 5) + random = context_variables["random"] + self.assertIn("data", context_variables) + data = context_variables["data"] + self.assertIn("authorization", context_variables) + self.assertEqual(len(context_variables["authorization"]), 32) + authorization = context_variables["authorization"] + self.assertEqual(gen_md5(TOKEN, data, random), authorization) + self.assertIn("SECRET_KEY", context_variables) + SECRET_KEY = context_variables["SECRET_KEY"] + self.assertEqual(SECRET_KEY, "DebugTalk") def test_get_parsed_request(self): test_runner = runner.Runner() testcase = { - "import_module_items": ["tests.debugtalk"], "variables": [ {"TOKEN": "debugtalk"}, {"random": "${gen_random_string(5)}"}, @@ -210,17 +202,19 @@ class VariableBindsUnittest(ApiServerUnittest): ], "request": { "url": "http://127.0.0.1:5000/api/users/1000", - "METHOD": "POST", - "Headers": { + "method": "POST", + "headers": { "Content-Type": "application/json", "authorization": "$authorization", "random": "$random", - "SECRET_KEY": "$SECRET_KEY" + "secret_key": "$SECRET_KEY" }, - "Data": "$data" + "data": "$data" } } - parsed_request = test_runner.init_config(testcase, level="testcase") + self.context.import_module_items(["tests.debugtalk"]) + self.context.bind_variables(testcase["variables"]) + parsed_request = self.context.get_parsed_request(testcase["request"]) self.assertIn("authorization", parsed_request["headers"]) self.assertEqual(len(parsed_request["headers"]["authorization"]), 32) self.assertIn("random", parsed_request["headers"])