mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
bugfix: substitute_variables_with_mapping, handle when value is None, bool, empty string
This commit is contained in:
@@ -192,7 +192,16 @@ def substitute_variables_with_mapping(content, mapping):
|
||||
}
|
||||
}
|
||||
"""
|
||||
if isinstance(content, (list, tuple)):
|
||||
if isinstance(content, bool):
|
||||
return content
|
||||
|
||||
if isinstance(content, (int, utils.long_type, float, complex)):
|
||||
return content
|
||||
|
||||
if not content:
|
||||
return content
|
||||
|
||||
if isinstance(content, (list, set, tuple)):
|
||||
return [
|
||||
substitute_variables_with_mapping(item, mapping)
|
||||
for item in content
|
||||
@@ -207,9 +216,6 @@ def substitute_variables_with_mapping(content, mapping):
|
||||
|
||||
return substituted_data
|
||||
|
||||
if isinstance(content, (int, utils.long_type, float, complex)):
|
||||
return content
|
||||
|
||||
# content is in string format here
|
||||
for var, value in mapping.items():
|
||||
if content == var:
|
||||
|
||||
@@ -428,7 +428,13 @@ class TestcaseParserUnittest(unittest.TestCase):
|
||||
'request': {
|
||||
'url': '/api/users/$uid',
|
||||
'method': "$method",
|
||||
'headers': {'token': '$token'}
|
||||
'headers': {'token': '$token'},
|
||||
'data': {
|
||||
"null": None,
|
||||
"true": True,
|
||||
"false": False,
|
||||
"empty_str": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
mapping = {
|
||||
@@ -439,6 +445,10 @@ class TestcaseParserUnittest(unittest.TestCase):
|
||||
self.assertEqual("/api/users/1000", result["request"]["url"])
|
||||
self.assertEqual("$token", result["request"]["headers"]["token"])
|
||||
self.assertEqual("POST", result["request"]["method"])
|
||||
self.assertIsNone(result["request"]["data"]["null"])
|
||||
self.assertTrue(result["request"]["data"]["true"])
|
||||
self.assertFalse(result["request"]["data"]["false"])
|
||||
self.assertEqual("", result["request"]["data"]["empty_str"])
|
||||
|
||||
def test_load_api_definition(self):
|
||||
path = os.path.join(
|
||||
|
||||
Reference in New Issue
Block a user