mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-10 23:12:41 +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 [
|
return [
|
||||||
substitute_variables_with_mapping(item, mapping)
|
substitute_variables_with_mapping(item, mapping)
|
||||||
for item in content
|
for item in content
|
||||||
@@ -207,9 +216,6 @@ def substitute_variables_with_mapping(content, mapping):
|
|||||||
|
|
||||||
return substituted_data
|
return substituted_data
|
||||||
|
|
||||||
if isinstance(content, (int, utils.long_type, float, complex)):
|
|
||||||
return content
|
|
||||||
|
|
||||||
# content is in string format here
|
# content is in string format here
|
||||||
for var, value in mapping.items():
|
for var, value in mapping.items():
|
||||||
if content == var:
|
if content == var:
|
||||||
|
|||||||
@@ -428,7 +428,13 @@ class TestcaseParserUnittest(unittest.TestCase):
|
|||||||
'request': {
|
'request': {
|
||||||
'url': '/api/users/$uid',
|
'url': '/api/users/$uid',
|
||||||
'method': "$method",
|
'method': "$method",
|
||||||
'headers': {'token': '$token'}
|
'headers': {'token': '$token'},
|
||||||
|
'data': {
|
||||||
|
"null": None,
|
||||||
|
"true": True,
|
||||||
|
"false": False,
|
||||||
|
"empty_str": ""
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mapping = {
|
mapping = {
|
||||||
@@ -439,6 +445,10 @@ class TestcaseParserUnittest(unittest.TestCase):
|
|||||||
self.assertEqual("/api/users/1000", result["request"]["url"])
|
self.assertEqual("/api/users/1000", result["request"]["url"])
|
||||||
self.assertEqual("$token", result["request"]["headers"]["token"])
|
self.assertEqual("$token", result["request"]["headers"]["token"])
|
||||||
self.assertEqual("POST", result["request"]["method"])
|
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):
|
def test_load_api_definition(self):
|
||||||
path = os.path.join(
|
path = os.path.join(
|
||||||
|
|||||||
Reference in New Issue
Block a user