mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-04 23:16:57 +08:00
fix #84: type_match invalid
This commit is contained in:
+12
-1
@@ -89,7 +89,18 @@ def contained_by(check_value, expect_value):
|
|||||||
assert check_value in expect_value
|
assert check_value in expect_value
|
||||||
|
|
||||||
def type_match(check_value, expect_value):
|
def type_match(check_value, expect_value):
|
||||||
assert isinstance(check_value, expect_value)
|
def get_type(name):
|
||||||
|
if isinstance(name, type):
|
||||||
|
return name
|
||||||
|
elif isinstance(name, str):
|
||||||
|
try:
|
||||||
|
return __builtins__[name]
|
||||||
|
except KeyError:
|
||||||
|
raise ValueError(name)
|
||||||
|
else:
|
||||||
|
raise ValueError(name)
|
||||||
|
|
||||||
|
assert isinstance(check_value, get_type(expect_value))
|
||||||
|
|
||||||
def regex_match(check_value, expect_value):
|
def regex_match(check_value, expect_value):
|
||||||
assert isinstance(expect_value, string_type)
|
assert isinstance(expect_value, string_type)
|
||||||
|
|||||||
@@ -11,3 +11,12 @@
|
|||||||
url: /api/users/1000
|
url: /api/users/1000
|
||||||
method: GET
|
method: GET
|
||||||
headers:
|
headers:
|
||||||
|
|
||||||
|
- test:
|
||||||
|
name: bugfix type_match #84
|
||||||
|
request:
|
||||||
|
url: http://127.0.0.1:5000/api/users/1000
|
||||||
|
method: GET
|
||||||
|
validate:
|
||||||
|
- eq: [status_code, 401]
|
||||||
|
- type_match: [status_code, int]
|
||||||
|
|||||||
@@ -144,3 +144,15 @@ class TestRunner(ApiServerUnittest):
|
|||||||
test_dict_headers
|
test_dict_headers
|
||||||
)
|
)
|
||||||
self.assertEqual(headers["Content-Type"], "application/json")
|
self.assertEqual(headers["Content-Type"], "application/json")
|
||||||
|
|
||||||
|
def test_bugfix_type_match(self):
|
||||||
|
testcase_file_path = os.path.join(
|
||||||
|
os.getcwd(), 'tests/data/test_bugfix.yml')
|
||||||
|
testcases = testcase._load_file(testcase_file_path)
|
||||||
|
config_dict = {
|
||||||
|
"path": testcase_file_path
|
||||||
|
}
|
||||||
|
self.test_runner.init_config(config_dict, "testset")
|
||||||
|
|
||||||
|
test = testcases[2]["test"]
|
||||||
|
self.assertTrue(self.test_runner._run_test(test))
|
||||||
|
|||||||
@@ -162,6 +162,9 @@ class TestUtils(ApiServerUnittest):
|
|||||||
functions_mapping["endswith"]("123abc", "abc")
|
functions_mapping["endswith"]("123abc", "abc")
|
||||||
functions_mapping["endswith"](12345, 45)
|
functions_mapping["endswith"](12345, 45)
|
||||||
|
|
||||||
|
functions_mapping["type_match"](580509390, int)
|
||||||
|
functions_mapping["type_match"](580509390, "int")
|
||||||
|
|
||||||
def test_deep_update_dict(self):
|
def test_deep_update_dict(self):
|
||||||
origin_dict = {'a': 1, 'b': {'c': 3, 'd': 4}, 'f': 6, 'h': 123}
|
origin_dict = {'a': 1, 'b': {'c': 3, 'd': 4}, 'f': 6, 'h': 123}
|
||||||
override_dict = {'a': 2, 'b': {'c': 33, 'e': 5}, 'g': 7, 'h': None}
|
override_dict = {'a': 2, 'b': {'c': 33, 'e': 5}, 'g': 7, 'h': None}
|
||||||
|
|||||||
Reference in New Issue
Block a user