mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-11 18:11:21 +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', {})
|
||||
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)
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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)}
|
||||
|
||||
@@ -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)}
|
||||
|
||||
@@ -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"])
|
||||
|
||||
Reference in New Issue
Block a user