mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-26 10:50:12 +08:00
rename keyword: variable_binds => variables
This commit is contained in:
@@ -54,8 +54,9 @@ class Context(object):
|
||||
or config_dict.get('import_module_functions', [])
|
||||
self.import_module_items(module_items, level)
|
||||
|
||||
variable_binds = config_dict.get('variable_binds', OrderedDict())
|
||||
self.bind_variables(variable_binds, level)
|
||||
variables = config_dict.get('variables') \
|
||||
or config_dict.get('variable_binds', OrderedDict())
|
||||
self.bind_variables(variables, level)
|
||||
|
||||
def import_requires(self, modules):
|
||||
""" import required modules dynamically
|
||||
@@ -92,11 +93,11 @@ class Context(object):
|
||||
imported_variables_dict = utils.filter_module(imported_module, "variable")
|
||||
self.bind_variables(imported_variables_dict, level)
|
||||
|
||||
def bind_variables(self, variable_binds, level="testcase"):
|
||||
def bind_variables(self, variables, 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.
|
||||
@param (list or OrderDict) variables, variable can be value or custom function.
|
||||
if value is function, it will be called and bind result to variable.
|
||||
e.g.
|
||||
OrderDict({
|
||||
@@ -106,10 +107,10 @@ class Context(object):
|
||||
"md5": "${gen_md5($TOKEN, $json, $random)}"
|
||||
})
|
||||
"""
|
||||
if isinstance(variable_binds, list):
|
||||
variable_binds = utils.convert_to_order_dict(variable_binds)
|
||||
if isinstance(variables, list):
|
||||
variables = utils.convert_to_order_dict(variables)
|
||||
|
||||
for variable_name, value in variable_binds.items():
|
||||
for variable_name, value in variables.items():
|
||||
variable_evale_value = self.testcase_parser.parse_content_with_bindings(value)
|
||||
|
||||
if level == "testset":
|
||||
|
||||
@@ -23,7 +23,7 @@ class Runner(object):
|
||||
"requires": [], # optional
|
||||
"function_binds": {}, # optional
|
||||
"import_module_items": [], # optional
|
||||
"variable_binds": [], # optional
|
||||
"variables": [], # optional
|
||||
"request": {
|
||||
"base_url": "http://127.0.0.1:5000",
|
||||
"headers": {
|
||||
@@ -37,7 +37,7 @@ class Runner(object):
|
||||
"requires": [], # optional
|
||||
"function_binds": {}, # optional
|
||||
"import_module_items": [], # optional
|
||||
"variable_binds": [], # optional
|
||||
"variables": [], # optional
|
||||
"request": {
|
||||
"url": "/api/get-token",
|
||||
"method": "POST",
|
||||
@@ -71,9 +71,9 @@ class Runner(object):
|
||||
{
|
||||
"name": "testcase description",
|
||||
"times": 3,
|
||||
"requires": [], # optional, override
|
||||
"function_binds": {}, # optional, override
|
||||
"variable_binds": [], # optional, override
|
||||
"requires": [], # optional, override
|
||||
"function_binds": {}, # optional, override
|
||||
"variables": [], # optional, override
|
||||
"request": {
|
||||
"url": "http://127.0.0.1:5000/api/users/1000",
|
||||
"method": "POST",
|
||||
@@ -136,13 +136,13 @@ class Runner(object):
|
||||
"name": "testset description",
|
||||
"requires": [],
|
||||
"function_binds": {},
|
||||
"variable_binds": [],
|
||||
"variables": [],
|
||||
"request": {}
|
||||
},
|
||||
"testcases": [
|
||||
{
|
||||
"name": "testcase description",
|
||||
"variable_binds": [], # optional, override
|
||||
"variables": [], # optional, override
|
||||
"request": {},
|
||||
"extractors": {}, # optional
|
||||
"validators": {} # optional
|
||||
@@ -151,7 +151,7 @@ class Runner(object):
|
||||
]
|
||||
}
|
||||
(dict) variables_mapping:
|
||||
passed in variables mapping, it will override variable_binds in config block
|
||||
passed in variables mapping, it will override variables in config block
|
||||
|
||||
@return (dict) test result of testset
|
||||
{
|
||||
@@ -162,9 +162,9 @@ class Runner(object):
|
||||
success = True
|
||||
config_dict = testset.get("config", {})
|
||||
|
||||
variable_binds = config_dict.get("variable_binds", [])
|
||||
variables = config_dict.get("variables", [])
|
||||
variables_mapping = variables_mapping or {}
|
||||
config_dict["variable_binds"] = utils.override_variables_binds(variable_binds, variables_mapping)
|
||||
config_dict["variables"] = utils.override_variables_binds(variables, variables_mapping)
|
||||
|
||||
self.init_config(config_dict, level="testset")
|
||||
testcases = testset.get("testcases", [])
|
||||
@@ -189,7 +189,7 @@ class Runner(object):
|
||||
- absolute/relative folder path
|
||||
- list/set container with file(s) and/or folder(s)
|
||||
(dict) mapping:
|
||||
passed in variables mapping, it will override variable_binds in config block
|
||||
passed in variables mapping, it will override variables in config block
|
||||
"""
|
||||
success = True
|
||||
mapping = mapping or {}
|
||||
|
||||
16
ate/utils.py
16
ate/utils.py
@@ -369,18 +369,18 @@ def update_ordered_dict(ordered_dict, override_mapping):
|
||||
|
||||
return ordered_dict
|
||||
|
||||
def override_variables_binds(variable_binds, new_mapping):
|
||||
""" convert variable_binds in testcase to ordered mapping, with new_mapping overrided
|
||||
def override_variables_binds(variables, new_mapping):
|
||||
""" convert variables in testcase to ordered mapping, with new_mapping overrided
|
||||
"""
|
||||
if isinstance(variable_binds, list):
|
||||
variable_binds_ordered_dict = convert_to_order_dict(variable_binds)
|
||||
elif isinstance(variable_binds, OrderedDict):
|
||||
variable_binds_ordered_dict = variable_binds
|
||||
if isinstance(variables, list):
|
||||
variables_ordered_dict = convert_to_order_dict(variables)
|
||||
elif isinstance(variables, OrderedDict):
|
||||
variables_ordered_dict = variables
|
||||
else:
|
||||
raise exception.ParamsError("variable_binds error!")
|
||||
raise exception.ParamsError("variables error!")
|
||||
|
||||
return update_ordered_dict(
|
||||
variable_binds_ordered_dict,
|
||||
variables_ordered_dict,
|
||||
new_mapping
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user