fix: validate with variable or function whose evaluation result is "" or not text

This commit is contained in:
debugtalk
2020-07-06 10:50:49 +08:00
parent 23cd0d9e65
commit 5673c0ca92
3 changed files with 28 additions and 2 deletions
+6
View File
@@ -1,5 +1,11 @@
# Release History # Release History
## 3.1.3 (2020-06-30)
**Fixed**
- fix: validate with variable or function whose evaluation result is "" or not text
## 3.1.2 (2020-06-29) ## 3.1.2 (2020-06-29)
**Fixed** **Fixed**
+5 -1
View File
@@ -197,7 +197,11 @@ class ResponseObject(object):
) )
check_item = parse_string_value(check_item) check_item = parse_string_value(check_item)
check_value = jmespath.search(check_item, self.resp_obj_meta) if check_item and isinstance(check_item, Text):
check_value = jmespath.search(check_item, self.resp_obj_meta)
else:
# variable or function evaluation result is "" or not text
check_value = check_item
# comparator # comparator
assert_method = u_validator["assert"] assert_method = u_validator["assert"]
+17 -1
View File
@@ -28,12 +28,28 @@ class TestResponse(unittest.TestCase):
self.assertEqual(extract_mapping["var_2"], "Olympia") self.assertEqual(extract_mapping["var_2"], "Olympia")
def test_validate(self): def test_validate(self):
variables_mapping = {"index": 1}
self.resp_obj.validate( self.resp_obj.validate(
[ [
{"eq": ["body.json.locations[0].name", "Seattle"]}, {"eq": ["body.json.locations[0].name", "Seattle"]},
{"eq": ["body.json.locations[0]", {"name": "Seattle", "state": "WA"}]}, {"eq": ["body.json.locations[0]", {"name": "Seattle", "state": "WA"}]},
],
)
def test_validate_variables(self):
variables_mapping = {"index": 1, "var_empty": ""}
self.resp_obj.validate(
[
{"eq": ["body.json.locations[$index].name", "New York"]}, {"eq": ["body.json.locations[$index].name", "New York"]},
{"eq": ["$var_empty", ""]},
], ],
variables_mapping=variables_mapping, variables_mapping=variables_mapping,
) )
def test_validate_functions(self):
variables_mapping = {"index": 1}
functions_mapping = {"get_num": lambda x: x}
self.resp_obj.validate(
[{"eq": ["${get_num(0)}", 0]}, {"eq": ["${get_num($index)}", 1]},],
variables_mapping=variables_mapping,
functions_mapping=functions_mapping,
)