mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-12 16:01:27 +08:00
rename keyword: variable_binds => variables
This commit is contained in:
@@ -75,7 +75,7 @@ And here is testset example of typical scenario: get `token` at the beginning, a
|
|||||||
```yaml
|
```yaml
|
||||||
- config:
|
- config:
|
||||||
name: "create user testsets."
|
name: "create user testsets."
|
||||||
variable_binds:
|
variables:
|
||||||
- user_agent: 'iOS/10.3'
|
- user_agent: 'iOS/10.3'
|
||||||
- device_sn: ${gen_random_string(15)}
|
- device_sn: ${gen_random_string(15)}
|
||||||
- os_platform: 'ios'
|
- os_platform: 'ios'
|
||||||
|
|||||||
@@ -54,8 +54,9 @@ class Context(object):
|
|||||||
or config_dict.get('import_module_functions', [])
|
or config_dict.get('import_module_functions', [])
|
||||||
self.import_module_items(module_items, level)
|
self.import_module_items(module_items, level)
|
||||||
|
|
||||||
variable_binds = config_dict.get('variable_binds', OrderedDict())
|
variables = config_dict.get('variables') \
|
||||||
self.bind_variables(variable_binds, level)
|
or config_dict.get('variable_binds', OrderedDict())
|
||||||
|
self.bind_variables(variables, level)
|
||||||
|
|
||||||
def import_requires(self, modules):
|
def import_requires(self, modules):
|
||||||
""" import required modules dynamically
|
""" import required modules dynamically
|
||||||
@@ -92,11 +93,11 @@ class Context(object):
|
|||||||
imported_variables_dict = utils.filter_module(imported_module, "variable")
|
imported_variables_dict = utils.filter_module(imported_module, "variable")
|
||||||
self.bind_variables(imported_variables_dict, level)
|
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.
|
""" 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.
|
||||||
|
|
||||||
@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.
|
if value is function, it will be called and bind result to variable.
|
||||||
e.g.
|
e.g.
|
||||||
OrderDict({
|
OrderDict({
|
||||||
@@ -106,10 +107,10 @@ class Context(object):
|
|||||||
"md5": "${gen_md5($TOKEN, $json, $random)}"
|
"md5": "${gen_md5($TOKEN, $json, $random)}"
|
||||||
})
|
})
|
||||||
"""
|
"""
|
||||||
if isinstance(variable_binds, list):
|
if isinstance(variables, list):
|
||||||
variable_binds = utils.convert_to_order_dict(variable_binds)
|
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)
|
variable_evale_value = self.testcase_parser.parse_content_with_bindings(value)
|
||||||
|
|
||||||
if level == "testset":
|
if level == "testset":
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ class Runner(object):
|
|||||||
"requires": [], # optional
|
"requires": [], # optional
|
||||||
"function_binds": {}, # optional
|
"function_binds": {}, # optional
|
||||||
"import_module_items": [], # optional
|
"import_module_items": [], # optional
|
||||||
"variable_binds": [], # optional
|
"variables": [], # optional
|
||||||
"request": {
|
"request": {
|
||||||
"base_url": "http://127.0.0.1:5000",
|
"base_url": "http://127.0.0.1:5000",
|
||||||
"headers": {
|
"headers": {
|
||||||
@@ -37,7 +37,7 @@ class Runner(object):
|
|||||||
"requires": [], # optional
|
"requires": [], # optional
|
||||||
"function_binds": {}, # optional
|
"function_binds": {}, # optional
|
||||||
"import_module_items": [], # optional
|
"import_module_items": [], # optional
|
||||||
"variable_binds": [], # optional
|
"variables": [], # optional
|
||||||
"request": {
|
"request": {
|
||||||
"url": "/api/get-token",
|
"url": "/api/get-token",
|
||||||
"method": "POST",
|
"method": "POST",
|
||||||
@@ -71,9 +71,9 @@ class Runner(object):
|
|||||||
{
|
{
|
||||||
"name": "testcase description",
|
"name": "testcase description",
|
||||||
"times": 3,
|
"times": 3,
|
||||||
"requires": [], # optional, override
|
"requires": [], # optional, override
|
||||||
"function_binds": {}, # optional, override
|
"function_binds": {}, # optional, override
|
||||||
"variable_binds": [], # optional, override
|
"variables": [], # optional, override
|
||||||
"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",
|
||||||
@@ -136,13 +136,13 @@ class Runner(object):
|
|||||||
"name": "testset description",
|
"name": "testset description",
|
||||||
"requires": [],
|
"requires": [],
|
||||||
"function_binds": {},
|
"function_binds": {},
|
||||||
"variable_binds": [],
|
"variables": [],
|
||||||
"request": {}
|
"request": {}
|
||||||
},
|
},
|
||||||
"testcases": [
|
"testcases": [
|
||||||
{
|
{
|
||||||
"name": "testcase description",
|
"name": "testcase description",
|
||||||
"variable_binds": [], # optional, override
|
"variables": [], # optional, override
|
||||||
"request": {},
|
"request": {},
|
||||||
"extractors": {}, # optional
|
"extractors": {}, # optional
|
||||||
"validators": {} # optional
|
"validators": {} # optional
|
||||||
@@ -151,7 +151,7 @@ class Runner(object):
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
(dict) variables_mapping:
|
(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
|
@return (dict) test result of testset
|
||||||
{
|
{
|
||||||
@@ -162,9 +162,9 @@ class Runner(object):
|
|||||||
success = True
|
success = True
|
||||||
config_dict = testset.get("config", {})
|
config_dict = testset.get("config", {})
|
||||||
|
|
||||||
variable_binds = config_dict.get("variable_binds", [])
|
variables = config_dict.get("variables", [])
|
||||||
variables_mapping = variables_mapping or {}
|
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")
|
self.init_config(config_dict, level="testset")
|
||||||
testcases = testset.get("testcases", [])
|
testcases = testset.get("testcases", [])
|
||||||
@@ -189,7 +189,7 @@ class Runner(object):
|
|||||||
- absolute/relative folder path
|
- absolute/relative folder path
|
||||||
- list/set container with file(s) and/or folder(s)
|
- list/set container with file(s) and/or folder(s)
|
||||||
(dict) mapping:
|
(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
|
success = True
|
||||||
mapping = mapping or {}
|
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
|
return ordered_dict
|
||||||
|
|
||||||
def override_variables_binds(variable_binds, new_mapping):
|
def override_variables_binds(variables, new_mapping):
|
||||||
""" convert variable_binds in testcase to ordered mapping, with new_mapping overrided
|
""" convert variables in testcase to ordered mapping, with new_mapping overrided
|
||||||
"""
|
"""
|
||||||
if isinstance(variable_binds, list):
|
if isinstance(variables, list):
|
||||||
variable_binds_ordered_dict = convert_to_order_dict(variable_binds)
|
variables_ordered_dict = convert_to_order_dict(variables)
|
||||||
elif isinstance(variable_binds, OrderedDict):
|
elif isinstance(variables, OrderedDict):
|
||||||
variable_binds_ordered_dict = variable_binds
|
variables_ordered_dict = variables
|
||||||
else:
|
else:
|
||||||
raise exception.ParamsError("variable_binds error!")
|
raise exception.ParamsError("variables error!")
|
||||||
|
|
||||||
return update_ordered_dict(
|
return update_ordered_dict(
|
||||||
variable_binds_ordered_dict,
|
variables_ordered_dict,
|
||||||
new_mapping
|
new_mapping
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ In actual scenarios, each user's `device_sn` is different, so we should paramete
|
|||||||
|
|
||||||
However, the test cases are only `YAML` documents, it is impossible to generate parameters dynamically in such text. Fortunately, we can combine `Python` scripts with `YAML/JSON` test cases in `ApiTestEngine`.
|
However, the test cases are only `YAML` documents, it is impossible to generate parameters dynamically in such text. Fortunately, we can combine `Python` scripts with `YAML/JSON` test cases in `ApiTestEngine`.
|
||||||
|
|
||||||
To achieve this goal, we can utilize `debugtalk.py` plugin and `variable_binds` mechanisms.
|
To achieve this goal, we can utilize `debugtalk.py` plugin and `variables` mechanisms.
|
||||||
|
|
||||||
To be specific, we can create a Python file (`examples/debugtalk.py`) and implement the related algorithm in it. The `debugtalk.py` file can not only be located beside `YAML/JSON` testset file, but also can be in any upward recursive folder. Since we want `debugtalk.py` to be importable, we should put a `__init__.py` in its folder to make it as a Python module.
|
To be specific, we can create a Python file (`examples/debugtalk.py`) and implement the related algorithm in it. The `debugtalk.py` file can not only be located beside `YAML/JSON` testset file, but also can be in any upward recursive folder. Since we want `debugtalk.py` to be importable, we should put a `__init__.py` in its folder to make it as a Python module.
|
||||||
|
|
||||||
@@ -187,7 +187,7 @@ And then, we can revise our demo test case and reference the functions. Suppose
|
|||||||
```yaml
|
```yaml
|
||||||
- test:
|
- test:
|
||||||
name: get token
|
name: get token
|
||||||
variable_binds:
|
variables:
|
||||||
- user_agent: 'iOS/10.3'
|
- user_agent: 'iOS/10.3'
|
||||||
- device_sn: ${gen_random_string(15)}
|
- device_sn: ${gen_random_string(15)}
|
||||||
- os_platform: 'ios'
|
- os_platform: 'ios'
|
||||||
@@ -226,7 +226,7 @@ And then, we can revise our demo test case and reference the functions. Suppose
|
|||||||
|
|
||||||
In this revised test case, `variable reference` and `function invoke` mechanisms are both used.
|
In this revised test case, `variable reference` and `function invoke` mechanisms are both used.
|
||||||
|
|
||||||
To make fields like `device_sn` can be used more than once, we bind values to variables in `variable_binds` block. When we bind variables, we can not only bind exact value to a variable name, but also can call a function and bind the evaluated value to it.
|
To make fields like `device_sn` can be used more than once, we bind values to variables in `variables` block. When we bind variables, we can not only bind exact value to a variable name, but also can call a function and bind the evaluated value to it.
|
||||||
|
|
||||||
When we want to reference a variable in the test case, we can do this with a escape character `$`. For example, `$user_agent` will not be taken as a normal string, and `ApiTestEngine` will consider it as a variable named `user_agent`, search and return its binding value.
|
When we want to reference a variable in the test case, we can do this with a escape character `$`. For example, `$user_agent` will not be taken as a normal string, and `ApiTestEngine` will consider it as a variable named `user_agent`, search and return its binding value.
|
||||||
|
|
||||||
@@ -244,7 +244,7 @@ To handle this case, overall `config` block is supported in `ApiTestEngine`. If
|
|||||||
# examples/quickstart-demo-rev-3.yml
|
# examples/quickstart-demo-rev-3.yml
|
||||||
- config:
|
- config:
|
||||||
name: "smoketest for CRUD users."
|
name: "smoketest for CRUD users."
|
||||||
variable_binds:
|
variables:
|
||||||
- device_sn: ${gen_random_string(15)}
|
- device_sn: ${gen_random_string(15)}
|
||||||
request:
|
request:
|
||||||
base_url: http://127.0.0.1:5000
|
base_url: http://127.0.0.1:5000
|
||||||
@@ -253,7 +253,7 @@ To handle this case, overall `config` block is supported in `ApiTestEngine`. If
|
|||||||
|
|
||||||
- test:
|
- test:
|
||||||
name: get token
|
name: get token
|
||||||
variable_binds:
|
variables:
|
||||||
- user_agent: 'iOS/10.3'
|
- user_agent: 'iOS/10.3'
|
||||||
- os_platform: 'ios'
|
- os_platform: 'ios'
|
||||||
- app_version: '2.8.6'
|
- app_version: '2.8.6'
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
- test:
|
- test:
|
||||||
name: get token
|
name: get token
|
||||||
variable_binds:
|
variables:
|
||||||
- user_agent: 'iOS/10.3'
|
- user_agent: 'iOS/10.3'
|
||||||
- device_sn: ${gen_random_string(15)}
|
- device_sn: ${gen_random_string(15)}
|
||||||
- os_platform: 'ios'
|
- os_platform: 'ios'
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
- config:
|
- config:
|
||||||
name: "smoketest for CRUD users."
|
name: "smoketest for CRUD users."
|
||||||
variable_binds:
|
variables:
|
||||||
- device_sn: ${gen_random_string(15)}
|
- device_sn: ${gen_random_string(15)}
|
||||||
request:
|
request:
|
||||||
base_url: http://127.0.0.1:5000
|
base_url: http://127.0.0.1:5000
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
- test:
|
- test:
|
||||||
name: get token
|
name: get token
|
||||||
variable_binds:
|
variables:
|
||||||
- user_agent: 'iOS/10.3'
|
- user_agent: 'iOS/10.3'
|
||||||
- os_platform: 'ios'
|
- os_platform: 'ios'
|
||||||
- app_version: '2.8.6'
|
- app_version: '2.8.6'
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
bind_variables:
|
bind_variables:
|
||||||
variable_binds:
|
variables:
|
||||||
- TOKEN: "debugtalk"
|
- TOKEN: "debugtalk"
|
||||||
- token: $TOKEN
|
- token: $TOKEN
|
||||||
|
|
||||||
@@ -7,7 +7,7 @@ bind_lambda_functions:
|
|||||||
function_binds:
|
function_binds:
|
||||||
add_one: "lambda x: x + 1"
|
add_one: "lambda x: x + 1"
|
||||||
add_two_nums: "lambda x, y: x + y"
|
add_two_nums: "lambda x, y: x + y"
|
||||||
variable_binds:
|
variables:
|
||||||
- add1: ${add_one(2)}
|
- add1: ${add_one(2)}
|
||||||
- sum2nums: ${add_two_nums(2, 3)}
|
- sum2nums: ${add_two_nums(2, 3)}
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ bind_lambda_functions_with_import:
|
|||||||
function_binds:
|
function_binds:
|
||||||
gen_random_string: "lambda str_len: ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(str_len))"
|
gen_random_string: "lambda str_len: ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(str_len))"
|
||||||
gen_md5: "lambda *str_args: hashlib.md5(''.join(str_args).encode('utf-8')).hexdigest()"
|
gen_md5: "lambda *str_args: hashlib.md5(''.join(str_args).encode('utf-8')).hexdigest()"
|
||||||
variable_binds:
|
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'}"
|
||||||
@@ -29,7 +29,7 @@ bind_module_functions:
|
|||||||
function_binds:
|
function_binds:
|
||||||
import_module_items:
|
import_module_items:
|
||||||
- tests.data.debugtalk
|
- tests.data.debugtalk
|
||||||
variable_binds:
|
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'}"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
- config:
|
- config:
|
||||||
name: "user management testset."
|
name: "user management testset."
|
||||||
variable_binds:
|
variables:
|
||||||
- user_agent: 'iOS/10.3'
|
- user_agent: 'iOS/10.3'
|
||||||
- device_sn: ${gen_random_string(15)}
|
- device_sn: ${gen_random_string(15)}
|
||||||
- os_platform: 'ios'
|
- os_platform: 'ios'
|
||||||
@@ -35,7 +35,7 @@
|
|||||||
|
|
||||||
- test:
|
- test:
|
||||||
name: create user which does not exist
|
name: create user which does not exist
|
||||||
variable_binds:
|
variables:
|
||||||
- user_name: "user1"
|
- user_name: "user1"
|
||||||
- user_password: "123456"
|
- user_password: "123456"
|
||||||
api: create_user(1000, $user_name, $user_password, $token)
|
api: create_user(1000, $user_name, $user_password, $token)
|
||||||
@@ -53,7 +53,7 @@
|
|||||||
|
|
||||||
- test:
|
- test:
|
||||||
name: create user which exists
|
name: create user which exists
|
||||||
variable_binds:
|
variables:
|
||||||
- user_name: "user1"
|
- user_name: "user1"
|
||||||
- user_password: "123456"
|
- user_password: "123456"
|
||||||
api: create_user(1000, $user_name, $user_password, $token)
|
api: create_user(1000, $user_name, $user_password, $token)
|
||||||
@@ -63,7 +63,7 @@
|
|||||||
|
|
||||||
- test:
|
- test:
|
||||||
name: update user which exists
|
name: update user which exists
|
||||||
variable_binds:
|
variables:
|
||||||
- user_name: "user1"
|
- user_name: "user1"
|
||||||
- user_password: "654321"
|
- user_password: "654321"
|
||||||
api: update_user(1000, $user_name, $user_password, $token)
|
api: update_user(1000, $user_name, $user_password, $token)
|
||||||
@@ -102,7 +102,7 @@
|
|||||||
|
|
||||||
- test:
|
- test:
|
||||||
name: create user which has been deleted
|
name: create user which has been deleted
|
||||||
variable_binds:
|
variables:
|
||||||
- user_name: "user1"
|
- user_name: "user1"
|
||||||
- user_password: "123456"
|
- user_password: "123456"
|
||||||
api: create_user(1000, $user_name, $user_password, $token)
|
api: create_user(1000, $user_name, $user_password, $token)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
name: "create user testsets."
|
name: "create user testsets."
|
||||||
import_module_items:
|
import_module_items:
|
||||||
- tests.data.debugtalk
|
- tests.data.debugtalk
|
||||||
variable_binds:
|
variables:
|
||||||
- user_agent: 'iOS/10.3'
|
- user_agent: 'iOS/10.3'
|
||||||
- device_sn: ${gen_random_string(15)}
|
- device_sn: ${gen_random_string(15)}
|
||||||
- os_platform: 'ios'
|
- os_platform: 'ios'
|
||||||
@@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
- test:
|
- test:
|
||||||
name: create user which does not exist
|
name: create user which does not exist
|
||||||
variable_binds:
|
variables:
|
||||||
- user_name: "user1"
|
- user_name: "user1"
|
||||||
- user_password: "123456"
|
- user_password: "123456"
|
||||||
request:
|
request:
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
'DebugTalk'.encode('ascii'),
|
'DebugTalk'.encode('ascii'),
|
||||||
''.join(args).encode('ascii'),
|
''.join(args).encode('ascii'),
|
||||||
hashlib.sha1).hexdigest()"
|
hashlib.sha1).hexdigest()"
|
||||||
variable_binds:
|
variables:
|
||||||
- user_agent: 'iOS/10.3'
|
- user_agent: 'iOS/10.3'
|
||||||
- device_sn: ${gen_random_string_lambda(15)}
|
- device_sn: ${gen_random_string_lambda(15)}
|
||||||
- os_platform: 'ios'
|
- os_platform: 'ios'
|
||||||
@@ -43,7 +43,7 @@
|
|||||||
|
|
||||||
- test:
|
- test:
|
||||||
name: create user which does not exist
|
name: create user which does not exist
|
||||||
variable_binds:
|
variables:
|
||||||
- user_name: "user1"
|
- user_name: "user1"
|
||||||
- user_password: "123456"
|
- user_password: "123456"
|
||||||
request:
|
request:
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
- config:
|
- config:
|
||||||
name: "create user testsets."
|
name: "create user testsets."
|
||||||
variable_binds:
|
variables:
|
||||||
- device_sn: 'HZfFBh6tU59EdXJ'
|
- device_sn: 'HZfFBh6tU59EdXJ'
|
||||||
request:
|
request:
|
||||||
base_url: $BASE_URL
|
base_url: $BASE_URL
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
- test:
|
- test:
|
||||||
name: get token
|
name: get token
|
||||||
variable_binds:
|
variables:
|
||||||
- user_agent: 'iOS/10.3'
|
- user_agent: 'iOS/10.3'
|
||||||
- os_platform: 'ios'
|
- os_platform: 'ios'
|
||||||
- app_version: '2.8.6'
|
- app_version: '2.8.6'
|
||||||
@@ -34,7 +34,7 @@
|
|||||||
|
|
||||||
- test:
|
- test:
|
||||||
name: create user which does not exist
|
name: create user which does not exist
|
||||||
variable_binds:
|
variables:
|
||||||
- user_name: "user1"
|
- user_name: "user1"
|
||||||
- user_password: "123456"
|
- user_password: "123456"
|
||||||
request:
|
request:
|
||||||
|
|||||||
@@ -18,11 +18,11 @@ class VariableBindsUnittest(unittest.TestCase):
|
|||||||
self.assertIn("get_timestamp", self.context.testset_functions_config)
|
self.assertIn("get_timestamp", self.context.testset_functions_config)
|
||||||
self.assertIn("gen_random_string", self.context.testset_functions_config)
|
self.assertIn("gen_random_string", self.context.testset_functions_config)
|
||||||
|
|
||||||
variable_binds = [
|
variables = [
|
||||||
{"random": "${gen_random_string(5)}"},
|
{"random": "${gen_random_string(5)}"},
|
||||||
{"timestamp10": "${get_timestamp(10)}"}
|
{"timestamp10": "${get_timestamp(10)}"}
|
||||||
]
|
]
|
||||||
self.context.bind_variables(variable_binds)
|
self.context.bind_variables(variables)
|
||||||
context_variables = self.context.get_testcase_variables_mapping()
|
context_variables = self.context.get_testcase_variables_mapping()
|
||||||
|
|
||||||
self.assertEqual(len(context_variables["random"]), 5)
|
self.assertEqual(len(context_variables["random"]), 5)
|
||||||
@@ -31,7 +31,7 @@ class VariableBindsUnittest(unittest.TestCase):
|
|||||||
def test_context_bind_testset_variables(self):
|
def test_context_bind_testset_variables(self):
|
||||||
# testcase in JSON format
|
# testcase in JSON format
|
||||||
testcase1 = {
|
testcase1 = {
|
||||||
"variable_binds": [
|
"variables": [
|
||||||
{"GLOBAL_TOKEN": "debugtalk"},
|
{"GLOBAL_TOKEN": "debugtalk"},
|
||||||
{"token": "$GLOBAL_TOKEN"}
|
{"token": "$GLOBAL_TOKEN"}
|
||||||
]
|
]
|
||||||
@@ -40,8 +40,8 @@ class VariableBindsUnittest(unittest.TestCase):
|
|||||||
testcase2 = self.testcases["bind_variables"]
|
testcase2 = self.testcases["bind_variables"]
|
||||||
|
|
||||||
for testcase in [testcase1, testcase2]:
|
for testcase in [testcase1, testcase2]:
|
||||||
variable_binds = testcase['variable_binds']
|
variables = testcase['variables']
|
||||||
self.context.bind_variables(variable_binds, level="testset")
|
self.context.bind_variables(variables, level="testset")
|
||||||
|
|
||||||
testset_variables = self.context.testset_shared_variables_mapping
|
testset_variables = self.context.testset_shared_variables_mapping
|
||||||
testcase_variables = self.context.get_testcase_variables_mapping()
|
testcase_variables = self.context.get_testcase_variables_mapping()
|
||||||
@@ -54,7 +54,7 @@ class VariableBindsUnittest(unittest.TestCase):
|
|||||||
|
|
||||||
def test_context_bind_testcase_variables(self):
|
def test_context_bind_testcase_variables(self):
|
||||||
testcase1 = {
|
testcase1 = {
|
||||||
"variable_binds": [
|
"variables": [
|
||||||
{"GLOBAL_TOKEN": "debugtalk"},
|
{"GLOBAL_TOKEN": "debugtalk"},
|
||||||
{"token": "$GLOBAL_TOKEN"}
|
{"token": "$GLOBAL_TOKEN"}
|
||||||
]
|
]
|
||||||
@@ -62,8 +62,8 @@ class VariableBindsUnittest(unittest.TestCase):
|
|||||||
testcase2 = self.testcases["bind_variables"]
|
testcase2 = self.testcases["bind_variables"]
|
||||||
|
|
||||||
for testcase in [testcase1, testcase2]:
|
for testcase in [testcase1, testcase2]:
|
||||||
variable_binds = testcase['variable_binds']
|
variables = testcase['variables']
|
||||||
self.context.bind_variables(variable_binds)
|
self.context.bind_variables(variables)
|
||||||
|
|
||||||
testset_variables = self.context.testset_shared_variables_mapping
|
testset_variables = self.context.testset_shared_variables_mapping
|
||||||
testcase_variables = self.context.get_testcase_variables_mapping()
|
testcase_variables = self.context.get_testcase_variables_mapping()
|
||||||
@@ -80,7 +80,7 @@ class VariableBindsUnittest(unittest.TestCase):
|
|||||||
"add_one": lambda x: x + 1,
|
"add_one": lambda x: x + 1,
|
||||||
"add_two_nums": lambda x, y: x + y
|
"add_two_nums": lambda x, y: x + y
|
||||||
},
|
},
|
||||||
"variable_binds": [
|
"variables": [
|
||||||
{"add1": "${add_one(2)}"},
|
{"add1": "${add_one(2)}"},
|
||||||
{"sum2nums": "${add_two_nums(2,3)}"}
|
{"sum2nums": "${add_two_nums(2,3)}"}
|
||||||
]
|
]
|
||||||
@@ -91,8 +91,8 @@ class VariableBindsUnittest(unittest.TestCase):
|
|||||||
function_binds = testcase.get('function_binds', {})
|
function_binds = testcase.get('function_binds', {})
|
||||||
self.context.bind_functions(function_binds)
|
self.context.bind_functions(function_binds)
|
||||||
|
|
||||||
variable_binds = testcase['variable_binds']
|
variables = testcase['variables']
|
||||||
self.context.bind_variables(variable_binds)
|
self.context.bind_variables(variables)
|
||||||
|
|
||||||
context_variables = self.context.get_testcase_variables_mapping()
|
context_variables = self.context.get_testcase_variables_mapping()
|
||||||
self.assertIn("add1", context_variables)
|
self.assertIn("add1", context_variables)
|
||||||
@@ -107,7 +107,7 @@ class VariableBindsUnittest(unittest.TestCase):
|
|||||||
"gen_random_string": "lambda str_len: ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(str_len))",
|
"gen_random_string": "lambda str_len: ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(str_len))",
|
||||||
"gen_md5": "lambda *str_args: hashlib.md5(''.join(str_args).encode('utf-8')).hexdigest()"
|
"gen_md5": "lambda *str_args: hashlib.md5(''.join(str_args).encode('utf-8')).hexdigest()"
|
||||||
},
|
},
|
||||||
"variable_binds": [
|
"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"}'},
|
||||||
@@ -123,8 +123,8 @@ class VariableBindsUnittest(unittest.TestCase):
|
|||||||
function_binds = testcase.get('function_binds', {})
|
function_binds = testcase.get('function_binds', {})
|
||||||
self.context.bind_functions(function_binds)
|
self.context.bind_functions(function_binds)
|
||||||
|
|
||||||
variable_binds = testcase['variable_binds']
|
variables = testcase['variables']
|
||||||
self.context.bind_variables(variable_binds)
|
self.context.bind_variables(variables)
|
||||||
context_variables = self.context.get_testcase_variables_mapping()
|
context_variables = self.context.get_testcase_variables_mapping()
|
||||||
|
|
||||||
self.assertIn("TOKEN", context_variables)
|
self.assertIn("TOKEN", context_variables)
|
||||||
@@ -144,7 +144,7 @@ class VariableBindsUnittest(unittest.TestCase):
|
|||||||
def test_import_module_items(self):
|
def test_import_module_items(self):
|
||||||
testcase1 = {
|
testcase1 = {
|
||||||
"import_module_items": ["tests.data.debugtalk"],
|
"import_module_items": ["tests.data.debugtalk"],
|
||||||
"variable_binds": [
|
"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"}'},
|
||||||
@@ -157,8 +157,8 @@ class VariableBindsUnittest(unittest.TestCase):
|
|||||||
module_items = testcase.get('import_module_items', [])
|
module_items = testcase.get('import_module_items', [])
|
||||||
self.context.import_module_items(module_items)
|
self.context.import_module_items(module_items)
|
||||||
|
|
||||||
variable_binds = testcase['variable_binds']
|
variables = testcase['variables']
|
||||||
self.context.bind_variables(variable_binds)
|
self.context.bind_variables(variables)
|
||||||
context_variables = self.context.get_testcase_variables_mapping()
|
context_variables = self.context.get_testcase_variables_mapping()
|
||||||
|
|
||||||
self.assertIn("TOKEN", context_variables)
|
self.assertIn("TOKEN", context_variables)
|
||||||
@@ -182,7 +182,7 @@ class VariableBindsUnittest(unittest.TestCase):
|
|||||||
test_runner = runner.Runner()
|
test_runner = runner.Runner()
|
||||||
testcase = {
|
testcase = {
|
||||||
"import_module_items": ["tests.data.debugtalk"],
|
"import_module_items": ["tests.data.debugtalk"],
|
||||||
"variable_binds": [
|
"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"}'},
|
||||||
@@ -206,7 +206,7 @@ class VariableBindsUnittest(unittest.TestCase):
|
|||||||
self.assertIn("random", parsed_request["headers"])
|
self.assertIn("random", parsed_request["headers"])
|
||||||
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["variables"][2]["data"])
|
||||||
self.assertEqual(parsed_request["headers"]["SECRET_KEY"], "DebugTalk")
|
self.assertEqual(parsed_request["headers"]["SECRET_KEY"], "DebugTalk")
|
||||||
|
|
||||||
def test_exec_content_functions(self):
|
def test_exec_content_functions(self):
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ class TestcaseParserUnittest(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def test_eval_content_variables(self):
|
def test_eval_content_variables(self):
|
||||||
variable_binds = {
|
variables = {
|
||||||
"var_1": "abc",
|
"var_1": "abc",
|
||||||
"var_2": "def",
|
"var_2": "def",
|
||||||
"var_3": 123,
|
"var_3": 123,
|
||||||
@@ -63,7 +63,7 @@ class TestcaseParserUnittest(unittest.TestCase):
|
|||||||
"var_5": True,
|
"var_5": True,
|
||||||
"var_6": None
|
"var_6": None
|
||||||
}
|
}
|
||||||
testcase_parser = testcase.TestcaseParser(variables_binds=variable_binds)
|
testcase_parser = testcase.TestcaseParser(variables_binds=variables)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
testcase_parser.eval_content_variables("$var_1"),
|
testcase_parser.eval_content_variables("$var_1"),
|
||||||
"abc"
|
"abc"
|
||||||
@@ -417,7 +417,7 @@ class TestcaseParserUnittest(unittest.TestCase):
|
|||||||
path = os.path.join(
|
path = os.path.join(
|
||||||
os.getcwd(), 'tests/data/demo_testset_layer.yml')
|
os.getcwd(), 'tests/data/demo_testset_layer.yml')
|
||||||
testsets_list = testcase.load_testcases_by_path(path)
|
testsets_list = testcase.load_testcases_by_path(path)
|
||||||
self.assertIn("variable_binds", testsets_list[0]["config"])
|
self.assertIn("variables", testsets_list[0]["config"])
|
||||||
self.assertIn("request", testsets_list[0]["config"])
|
self.assertIn("request", testsets_list[0]["config"])
|
||||||
self.assertIn("request", testsets_list[0]["testcases"][0])
|
self.assertIn("request", testsets_list[0]["testcases"][0])
|
||||||
self.assertIn("url", testsets_list[0]["testcases"][0]["request"])
|
self.assertIn("url", testsets_list[0]["testcases"][0]["request"])
|
||||||
|
|||||||
Reference in New Issue
Block a user