mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 07:26:55 +08:00
hot plugin support: search variables recursive upward from testset file
This commit is contained in:
+1
-1
@@ -1 +1 @@
|
|||||||
__version__ = '0.6.0'
|
__version__ = '0.6.1'
|
||||||
+6
-2
@@ -39,7 +39,7 @@ class Context(object):
|
|||||||
self.testcase_parser.bind_variables(self.testcase_variables_mapping)
|
self.testcase_parser.bind_variables(self.testcase_variables_mapping)
|
||||||
|
|
||||||
if level == "testset":
|
if level == "testset":
|
||||||
self.import_module_functions(["ate.built_in"], "testset")
|
self.import_module_items(["ate.built_in"], "testset")
|
||||||
|
|
||||||
def import_requires(self, modules):
|
def import_requires(self, modules):
|
||||||
""" import required modules dynamicly
|
""" import required modules dynamicly
|
||||||
@@ -64,7 +64,7 @@ class Context(object):
|
|||||||
|
|
||||||
self.__update_context_functions_config(level, eval_function_binds)
|
self.__update_context_functions_config(level, eval_function_binds)
|
||||||
|
|
||||||
def import_module_functions(self, modules, level="testcase"):
|
def import_module_items(self, modules, level="testcase"):
|
||||||
""" import modules and bind all functions within the context
|
""" import modules and bind all functions within the context
|
||||||
"""
|
"""
|
||||||
sys.path.insert(0, os.getcwd())
|
sys.path.insert(0, os.getcwd())
|
||||||
@@ -73,6 +73,10 @@ class Context(object):
|
|||||||
imported_functions_dict = utils.filter_module(imported_module, "function")
|
imported_functions_dict = utils.filter_module(imported_module, "function")
|
||||||
self.__update_context_functions_config(level, imported_functions_dict)
|
self.__update_context_functions_config(level, imported_functions_dict)
|
||||||
|
|
||||||
|
imported_variables_dict = utils.filter_module(imported_module, "variable")
|
||||||
|
variable_binds = [{key: value} for key, value in imported_variables_dict.items()]
|
||||||
|
self.bind_variables(variable_binds, level)
|
||||||
|
|
||||||
def bind_variables(self, variable_binds, level="testcase"):
|
def bind_variables(self, variable_binds, level="testcase"):
|
||||||
""" bind variables to testset context or current testcase context.
|
""" bind variables to testset context or current testcase context.
|
||||||
variables in testset context can be used in all testcases of current test suite.
|
variables in testset context can be used in all testcases of current test suite.
|
||||||
|
|||||||
+5
-3
@@ -25,7 +25,7 @@ class Runner(object):
|
|||||||
"lambda *str_args: hashlib.md5(''.join(str_args).\
|
"lambda *str_args: hashlib.md5(''.join(str_args).\
|
||||||
encode('utf-8')).hexdigest()"
|
encode('utf-8')).hexdigest()"
|
||||||
},
|
},
|
||||||
"import_module_functions": ["test.data.debugtalk"],
|
"import_module_items": ["test.data.debugtalk"],
|
||||||
"variable_binds": [
|
"variable_binds": [
|
||||||
{"TOKEN": "debugtalk"},
|
{"TOKEN": "debugtalk"},
|
||||||
{"random": "${gen_random_string(5)}"},
|
{"random": "${gen_random_string(5)}"},
|
||||||
@@ -41,8 +41,10 @@ class Runner(object):
|
|||||||
function_binds = config_dict.get('function_binds', {})
|
function_binds = config_dict.get('function_binds', {})
|
||||||
self.context.bind_functions(function_binds, level)
|
self.context.bind_functions(function_binds, level)
|
||||||
|
|
||||||
module_functions = config_dict.get('import_module_functions', [])
|
# import_module_functions will be deprecated soon
|
||||||
self.context.import_module_functions(module_functions, level)
|
module_items = config_dict.get('import_module_items', []) \
|
||||||
|
or config_dict.get('import_module_functions', [])
|
||||||
|
self.context.import_module_items(module_items, level)
|
||||||
|
|
||||||
variable_binds = config_dict.get('variable_binds', [])
|
variable_binds = config_dict.get('variable_binds', [])
|
||||||
self.context.bind_variables(variable_binds, level)
|
self.context.bind_variables(variable_binds, level)
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ bind_lambda_functions_with_import:
|
|||||||
|
|
||||||
bind_module_functions:
|
bind_module_functions:
|
||||||
function_binds:
|
function_binds:
|
||||||
import_module_functions:
|
import_module_items:
|
||||||
- tests.data.debugtalk
|
- tests.data.debugtalk
|
||||||
variable_binds:
|
variable_binds:
|
||||||
- TOKEN: debugtalk
|
- TOKEN: debugtalk
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
- config:
|
- config:
|
||||||
name: "create user testsets."
|
name: "create user testsets."
|
||||||
import_module_functions:
|
import_module_items:
|
||||||
- tests.data.debugtalk
|
- tests.data.debugtalk
|
||||||
variable_binds:
|
variable_binds:
|
||||||
- user_agent: 'iOS/10.3'
|
- user_agent: 'iOS/10.3'
|
||||||
|
|||||||
+11
-7
@@ -140,9 +140,9 @@ class VariableBindsUnittest(unittest.TestCase):
|
|||||||
authorization = context_variables["authorization"]
|
authorization = context_variables["authorization"]
|
||||||
self.assertEqual(utils.gen_md5(TOKEN, data, random), authorization)
|
self.assertEqual(utils.gen_md5(TOKEN, data, random), authorization)
|
||||||
|
|
||||||
def test_import_module_functions(self):
|
def test_import_module_items(self):
|
||||||
testcase1 = {
|
testcase1 = {
|
||||||
"import_module_functions": ["tests.data.debugtalk"],
|
"import_module_items": ["tests.data.debugtalk"],
|
||||||
"variable_binds": [
|
"variable_binds": [
|
||||||
{"TOKEN": "debugtalk"},
|
{"TOKEN": "debugtalk"},
|
||||||
{"random": "${gen_random_string(5)}"},
|
{"random": "${gen_random_string(5)}"},
|
||||||
@@ -153,8 +153,8 @@ class VariableBindsUnittest(unittest.TestCase):
|
|||||||
testcase2 = self.testcases["bind_module_functions"]
|
testcase2 = self.testcases["bind_module_functions"]
|
||||||
|
|
||||||
for testcase in [testcase1, testcase2]:
|
for testcase in [testcase1, testcase2]:
|
||||||
module_functions = testcase.get('import_module_functions', [])
|
module_items = testcase.get('import_module_items', [])
|
||||||
self.context.import_module_functions(module_functions)
|
self.context.import_module_items(module_items)
|
||||||
|
|
||||||
variable_binds = testcase['variable_binds']
|
variable_binds = testcase['variable_binds']
|
||||||
self.context.bind_variables(variable_binds)
|
self.context.bind_variables(variable_binds)
|
||||||
@@ -173,6 +173,9 @@ class VariableBindsUnittest(unittest.TestCase):
|
|||||||
self.assertEqual(len(context_variables["authorization"]), 32)
|
self.assertEqual(len(context_variables["authorization"]), 32)
|
||||||
authorization = context_variables["authorization"]
|
authorization = context_variables["authorization"]
|
||||||
self.assertEqual(utils.gen_md5(TOKEN, data, random), authorization)
|
self.assertEqual(utils.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_register_request(self):
|
def test_register_request(self):
|
||||||
request_dict = {
|
request_dict = {
|
||||||
@@ -195,11 +198,10 @@ class VariableBindsUnittest(unittest.TestCase):
|
|||||||
with self.assertRaises(ParamsError):
|
with self.assertRaises(ParamsError):
|
||||||
self.context.register_request(request_dict)
|
self.context.register_request(request_dict)
|
||||||
|
|
||||||
|
|
||||||
def test_get_parsed_request(self):
|
def test_get_parsed_request(self):
|
||||||
test_runner = runner.Runner()
|
test_runner = runner.Runner()
|
||||||
testcase = {
|
testcase = {
|
||||||
"import_module_functions": ["tests.data.debugtalk"],
|
"import_module_items": ["tests.data.debugtalk"],
|
||||||
"variable_binds": [
|
"variable_binds": [
|
||||||
{"TOKEN": "debugtalk"},
|
{"TOKEN": "debugtalk"},
|
||||||
{"random": "${gen_random_string(5)}"},
|
{"random": "${gen_random_string(5)}"},
|
||||||
@@ -212,7 +214,8 @@ class VariableBindsUnittest(unittest.TestCase):
|
|||||||
"headers": {
|
"headers": {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"authorization": "$authorization",
|
"authorization": "$authorization",
|
||||||
"random": "$random"
|
"random": "$random",
|
||||||
|
"SECRET_KEY": "$SECRET_KEY"
|
||||||
},
|
},
|
||||||
"data": "$data"
|
"data": "$data"
|
||||||
}
|
}
|
||||||
@@ -225,3 +228,4 @@ class VariableBindsUnittest(unittest.TestCase):
|
|||||||
self.assertEqual(len(parsed_request["headers"]["random"]), 5)
|
self.assertEqual(len(parsed_request["headers"]["random"]), 5)
|
||||||
self.assertIn("data", parsed_request)
|
self.assertIn("data", parsed_request)
|
||||||
self.assertEqual(parsed_request["data"], testcase["variable_binds"][2]["data"])
|
self.assertEqual(parsed_request["data"], testcase["variable_binds"][2]["data"])
|
||||||
|
self.assertEqual(parsed_request["headers"]["secret_key"], "DebugTalk")
|
||||||
|
|||||||
Reference in New Issue
Block a user