mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-12 16:01:27 +08:00
remove unused code: substitute_variables
This commit is contained in:
@@ -207,61 +207,6 @@ def parse_validator(validator):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def substitute_variables(content, variables_mapping):
|
|
||||||
""" substitute variables in content with variables_mapping
|
|
||||||
|
|
||||||
Args:
|
|
||||||
content (str/dict/list/numeric/bool/type): content to be substituted.
|
|
||||||
variables_mapping (dict): variables mapping.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
substituted content.
|
|
||||||
|
|
||||||
Examples:
|
|
||||||
>>> content = {
|
|
||||||
'request': {
|
|
||||||
'url': '/api/users/$uid',
|
|
||||||
'headers': {'token': '$token'}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
>>> variables_mapping = {"$uid": 1000}
|
|
||||||
>>> substitute_variables(content, variables_mapping)
|
|
||||||
{
|
|
||||||
'request': {
|
|
||||||
'url': '/api/users/1000',
|
|
||||||
'headers': {'token': '$token'}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
"""
|
|
||||||
if isinstance(content, (list, set, tuple)):
|
|
||||||
return [
|
|
||||||
substitute_variables(item, variables_mapping)
|
|
||||||
for item in content
|
|
||||||
]
|
|
||||||
|
|
||||||
if isinstance(content, dict):
|
|
||||||
substituted_data = {}
|
|
||||||
for key, value in content.items():
|
|
||||||
eval_key = substitute_variables(key, variables_mapping)
|
|
||||||
eval_value = substitute_variables(value, variables_mapping)
|
|
||||||
substituted_data[eval_key] = eval_value
|
|
||||||
|
|
||||||
return substituted_data
|
|
||||||
|
|
||||||
if isinstance(content, basestring):
|
|
||||||
# content is in string format here
|
|
||||||
for var, value in variables_mapping.items():
|
|
||||||
if content == var:
|
|
||||||
# content is a variable
|
|
||||||
content = value
|
|
||||||
else:
|
|
||||||
if not isinstance(value, str):
|
|
||||||
value = builtin_str(value)
|
|
||||||
content = content.replace(var, value)
|
|
||||||
|
|
||||||
return content
|
|
||||||
|
|
||||||
def parse_parameters(parameters, variables_mapping=None, functions_mapping=None):
|
def parse_parameters(parameters, variables_mapping=None, functions_mapping=None):
|
||||||
""" parse parameters and generate cartesian product.
|
""" parse parameters and generate cartesian product.
|
||||||
|
|
||||||
|
|||||||
@@ -345,18 +345,6 @@ class TestParser(unittest.TestCase):
|
|||||||
3
|
3
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_substitute_variables(self):
|
|
||||||
content = {
|
|
||||||
'request': {
|
|
||||||
'url': '/api/users/$uid?id=$id',
|
|
||||||
'headers': {'token': '$token'}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
variables_mapping = {"$uid": 1000, "$id": 2}
|
|
||||||
substituted_data = parser.substitute_variables(content, variables_mapping)
|
|
||||||
self.assertEqual(substituted_data["request"]["url"], "/api/users/1000?id=2")
|
|
||||||
self.assertEqual(substituted_data["request"]["headers"], {'token': '$token'})
|
|
||||||
|
|
||||||
def test_parse_parameters_raw_list(self):
|
def test_parse_parameters_raw_list(self):
|
||||||
parameters = [
|
parameters = [
|
||||||
{"user_agent": ["iOS/10.1", "iOS/10.2", "iOS/10.3"]},
|
{"user_agent": ["iOS/10.1", "iOS/10.2", "iOS/10.3"]},
|
||||||
|
|||||||
Reference in New Issue
Block a user