mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-18 09:57:37 +08:00
#78: merge validators in test with api validators
This commit is contained in:
@@ -11,8 +11,8 @@
|
||||
json:
|
||||
sign: ${get_sign($user_agent, $device_sn, $os_platform, $app_version)}
|
||||
validate:
|
||||
- {"check": "status_code", "comparator": "eq", "expect": 200}
|
||||
- {"check": "content.token", "comparator": "len_eq", "expect": 16}
|
||||
- "eq": ["status_code", 0]
|
||||
- "len_eq": ["content.token", 12]
|
||||
|
||||
- api:
|
||||
def: create_user($uid, $user_name, $user_password, $token)
|
||||
|
||||
@@ -18,6 +18,9 @@
|
||||
api: get_token($user_agent, $device_sn, $os_platform, $app_version)
|
||||
extract:
|
||||
- token: content.token
|
||||
validate:
|
||||
- "eq": ["status_code", 200]
|
||||
- "len_eq": ["content.token", 16]
|
||||
|
||||
- test:
|
||||
name: reset all users
|
||||
|
||||
@@ -220,10 +220,10 @@ class VariableBindsUnittest(ApiServerUnittest):
|
||||
|
||||
def test_do_validation(self):
|
||||
self.context.do_validation(
|
||||
{"check_item": "check_item", "check_value": 1, "expect_value": 1, "comparator": "eq"}
|
||||
{"check": "check", "check_value": 1, "expect": 1, "comparator": "eq"}
|
||||
)
|
||||
self.context.do_validation(
|
||||
{"check_item": "check_item", "check_value": "abc", "expect_value": "abc", "comparator": "=="}
|
||||
{"check": "check", "check_value": "abc", "expect": "abc", "comparator": "=="}
|
||||
)
|
||||
|
||||
config_dict = {
|
||||
@@ -231,7 +231,7 @@ class VariableBindsUnittest(ApiServerUnittest):
|
||||
}
|
||||
self.context.config_context(config_dict, "testset")
|
||||
self.context.do_validation(
|
||||
{"check_item": "status_code", "check_value": "201", "expect_value": 3, "comparator": "sum_status_code"}
|
||||
{"check": "status_code", "check_value": "201", "expect": 3, "comparator": "sum_status_code"}
|
||||
)
|
||||
|
||||
def test_validate(self):
|
||||
|
||||
@@ -542,3 +542,40 @@ class TestcaseParserUnittest(unittest.TestCase):
|
||||
|
||||
with self.assertRaises(ApiNotFound):
|
||||
testcase.get_test_definition("api_not_exist", "api")
|
||||
|
||||
def test_parse_validator(self):
|
||||
validator = {"check": "status_code", "comparator": "eq", "expect": 201}
|
||||
self.assertEqual(
|
||||
testcase.parse_validator(validator),
|
||||
{"check": "status_code", "comparator": "eq", "expect": 201}
|
||||
)
|
||||
|
||||
validator = {'eq': ['status_code', 201]}
|
||||
self.assertEqual(
|
||||
testcase.parse_validator(validator),
|
||||
{"check": "status_code", "comparator": "eq", "expect": 201}
|
||||
)
|
||||
|
||||
def test_merge_validator(self):
|
||||
api_validators = [
|
||||
{'eq': ['v1', 200]},
|
||||
{"check": "s2", "expect": 16, "comparator": "len_eq"}
|
||||
]
|
||||
test_validators = [
|
||||
{"check": "v1", "expect": 201},
|
||||
{'len_eq': ['s3', 12]}
|
||||
]
|
||||
|
||||
merged_validators = testcase.merge_validator(api_validators, test_validators)
|
||||
self.assertIn(
|
||||
{"check": "v1", "expect": 201, "comparator": "eq"},
|
||||
merged_validators
|
||||
)
|
||||
self.assertIn(
|
||||
{"check": "s2", "expect": 16, "comparator": "len_eq"},
|
||||
merged_validators
|
||||
)
|
||||
self.assertIn(
|
||||
{"check": "s3", "expect": 12, "comparator": "len_eq"},
|
||||
merged_validators
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user