fix #84: type_match invalid

This commit is contained in:
debugtalk
2018-01-17 12:49:02 +08:00
parent f1a5eb56c0
commit c40a208024
4 changed files with 36 additions and 1 deletions

View File

@@ -89,7 +89,18 @@ def contained_by(check_value, expect_value):
assert check_value in 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):
assert isinstance(expect_value, string_type)

View File

@@ -11,3 +11,12 @@
url: /api/users/1000
method: GET
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]

View File

@@ -144,3 +144,15 @@ class TestRunner(ApiServerUnittest):
test_dict_headers
)
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))

View File

@@ -162,6 +162,9 @@ class TestUtils(ApiServerUnittest):
functions_mapping["endswith"]("123abc", "abc")
functions_mapping["endswith"](12345, 45)
functions_mapping["type_match"](580509390, int)
functions_mapping["type_match"](580509390, "int")
def test_deep_update_dict(self):
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}