mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-04 23:16:57 +08:00
deprecate import_module_items
This commit is contained in:
@@ -51,11 +51,6 @@ class Context(object):
|
|||||||
function_binds = config_dict.get('function_binds', {})
|
function_binds = config_dict.get('function_binds', {})
|
||||||
self.bind_functions(function_binds, level)
|
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') \
|
variables = config_dict.get('variables') \
|
||||||
or config_dict.get('variable_binds', OrderedDict())
|
or config_dict.get('variable_binds', OrderedDict())
|
||||||
self.bind_variables(variables, level)
|
self.bind_variables(variables, level)
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ class Runner(object):
|
|||||||
"path": "tests/data/demo_testset_variables.yml",
|
"path": "tests/data/demo_testset_variables.yml",
|
||||||
"requires": [], # optional
|
"requires": [], # optional
|
||||||
"function_binds": {}, # optional
|
"function_binds": {}, # optional
|
||||||
"import_module_items": [], # optional
|
|
||||||
"variables": [], # optional
|
"variables": [], # optional
|
||||||
"request": {
|
"request": {
|
||||||
"base_url": "http://127.0.0.1:5000",
|
"base_url": "http://127.0.0.1:5000",
|
||||||
@@ -52,7 +51,6 @@ class Runner(object):
|
|||||||
"name": "testcase description",
|
"name": "testcase description",
|
||||||
"requires": [], # optional
|
"requires": [], # optional
|
||||||
"function_binds": {}, # optional
|
"function_binds": {}, # optional
|
||||||
"import_module_items": [], # optional
|
|
||||||
"variables": [], # optional
|
"variables": [], # optional
|
||||||
"request": {
|
"request": {
|
||||||
"url": "/api/get-token",
|
"url": "/api/get-token",
|
||||||
|
|||||||
@@ -25,16 +25,6 @@ bind_lambda_functions_with_import:
|
|||||||
- data: "{'name': 'user', 'password': '123456'}"
|
- data: "{'name': 'user', 'password': '123456'}"
|
||||||
- authorization: ${gen_md5($TOKEN, $data, $random)}
|
- 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:
|
builtin_functions:
|
||||||
variables:
|
variables:
|
||||||
- length: ${len(debugtalk)}
|
- length: ${len(debugtalk)}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
- config:
|
- config:
|
||||||
name: "create user testsets."
|
name: "create user testsets."
|
||||||
import_module_items:
|
|
||||||
- tests.debugtalk
|
|
||||||
variables:
|
variables:
|
||||||
- user_agent: 'iOS/10.3'
|
- user_agent: 'iOS/10.3'
|
||||||
- device_sn: ${gen_random_string(15)}
|
- device_sn: ${gen_random_string(15)}
|
||||||
|
|||||||
+33
-39
@@ -162,46 +162,38 @@ class VariableBindsUnittest(ApiServerUnittest):
|
|||||||
self.assertEqual(gen_md5(TOKEN, data, random), authorization)
|
self.assertEqual(gen_md5(TOKEN, data, random), authorization)
|
||||||
|
|
||||||
def test_import_module_items(self):
|
def test_import_module_items(self):
|
||||||
testcase1 = {
|
module_items = ["tests.debugtalk"]
|
||||||
"import_module_items": ["tests.debugtalk"],
|
variables = [
|
||||||
"variables": [
|
{"TOKEN": "debugtalk"},
|
||||||
{"TOKEN": "debugtalk"},
|
{"random": "${gen_random_string(5)}"},
|
||||||
{"random": "${gen_random_string(5)}"},
|
{"data": '{"name": "user", "password": "123456"}'},
|
||||||
{"data": '{"name": "user", "password": "123456"}'},
|
{"authorization": "${gen_md5($TOKEN, $data, $random)}"}
|
||||||
{"authorization": "${gen_md5($TOKEN, $data, $random)}"}
|
]
|
||||||
]
|
|
||||||
}
|
|
||||||
testcase2 = self.testcases["bind_module_functions"]
|
|
||||||
|
|
||||||
for testcase in [testcase1, testcase2]:
|
self.context.import_module_items(module_items)
|
||||||
module_items = testcase.get('import_module_items', [])
|
self.context.bind_variables(variables)
|
||||||
self.context.import_module_items(module_items)
|
context_variables = self.context.testcase_variables_mapping
|
||||||
|
|
||||||
variables = testcase['variables']
|
self.assertIn("TOKEN", context_variables)
|
||||||
self.context.bind_variables(variables)
|
TOKEN = context_variables["TOKEN"]
|
||||||
context_variables = self.context.testcase_variables_mapping
|
self.assertEqual(TOKEN, "debugtalk")
|
||||||
|
self.assertIn("random", context_variables)
|
||||||
self.assertIn("TOKEN", context_variables)
|
self.assertIsInstance(context_variables["random"], str)
|
||||||
TOKEN = context_variables["TOKEN"]
|
self.assertEqual(len(context_variables["random"]), 5)
|
||||||
self.assertEqual(TOKEN, "debugtalk")
|
random = context_variables["random"]
|
||||||
self.assertIn("random", context_variables)
|
self.assertIn("data", context_variables)
|
||||||
self.assertIsInstance(context_variables["random"], str)
|
data = context_variables["data"]
|
||||||
self.assertEqual(len(context_variables["random"]), 5)
|
self.assertIn("authorization", context_variables)
|
||||||
random = context_variables["random"]
|
self.assertEqual(len(context_variables["authorization"]), 32)
|
||||||
self.assertIn("data", context_variables)
|
authorization = context_variables["authorization"]
|
||||||
data = context_variables["data"]
|
self.assertEqual(gen_md5(TOKEN, data, random), authorization)
|
||||||
self.assertIn("authorization", context_variables)
|
self.assertIn("SECRET_KEY", context_variables)
|
||||||
self.assertEqual(len(context_variables["authorization"]), 32)
|
SECRET_KEY = context_variables["SECRET_KEY"]
|
||||||
authorization = context_variables["authorization"]
|
self.assertEqual(SECRET_KEY, "DebugTalk")
|
||||||
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):
|
def test_get_parsed_request(self):
|
||||||
test_runner = runner.Runner()
|
test_runner = runner.Runner()
|
||||||
testcase = {
|
testcase = {
|
||||||
"import_module_items": ["tests.debugtalk"],
|
|
||||||
"variables": [
|
"variables": [
|
||||||
{"TOKEN": "debugtalk"},
|
{"TOKEN": "debugtalk"},
|
||||||
{"random": "${gen_random_string(5)}"},
|
{"random": "${gen_random_string(5)}"},
|
||||||
@@ -210,17 +202,19 @@ class VariableBindsUnittest(ApiServerUnittest):
|
|||||||
],
|
],
|
||||||
"request": {
|
"request": {
|
||||||
"url": "http://127.0.0.1:5000/api/users/1000",
|
"url": "http://127.0.0.1:5000/api/users/1000",
|
||||||
"METHOD": "POST",
|
"method": "POST",
|
||||||
"Headers": {
|
"headers": {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"authorization": "$authorization",
|
"authorization": "$authorization",
|
||||||
"random": "$random",
|
"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.assertIn("authorization", parsed_request["headers"])
|
||||||
self.assertEqual(len(parsed_request["headers"]["authorization"]), 32)
|
self.assertEqual(len(parsed_request["headers"]["authorization"]), 32)
|
||||||
self.assertIn("random", parsed_request["headers"])
|
self.assertIn("random", parsed_request["headers"])
|
||||||
|
|||||||
Reference in New Issue
Block a user