mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
rename validators to validate
This commit is contained in:
@@ -100,7 +100,7 @@ And here is testset example of typical scenario: get `token` at the beginning, a
|
||||
sign: ${get_sign($user_agent, $device_sn, $os_platform, $app_version)}
|
||||
extract:
|
||||
- token: content.token
|
||||
validators:
|
||||
validate:
|
||||
- {"check": "status_code", "comparator": "eq", "expected": 200}
|
||||
- {"check": "content.token", "comparator": "len_eq", "expected": 16}
|
||||
|
||||
@@ -114,7 +114,7 @@ And here is testset example of typical scenario: get `token` at the beginning, a
|
||||
json:
|
||||
name: "user1"
|
||||
password: "123456"
|
||||
validators:
|
||||
validate:
|
||||
- {"check": "status_code", "comparator": "eq", "expected": 201}
|
||||
- {"check": "content.success", "comparator": "eq", "expected": true}
|
||||
```
|
||||
|
||||
@@ -86,7 +86,7 @@ class Runner(object):
|
||||
"body": '{"name": "user", "password": "123456"}'
|
||||
},
|
||||
"extract": [], # optional
|
||||
"validators": [], # optional
|
||||
"validate": [], # optional
|
||||
"setup": [], # optional
|
||||
"teardown": [] # optional
|
||||
}
|
||||
@@ -104,7 +104,8 @@ class Runner(object):
|
||||
run_times = int(testcase.get("times", 1))
|
||||
extractors = testcase.get("extract") \
|
||||
or testcase.get("extract_binds", [])
|
||||
validators = testcase.get("validators", [])
|
||||
validators = testcase.get("validate") \
|
||||
or testcase.get("validators", [])
|
||||
setup_actions = testcase.get("setup", [])
|
||||
teardown_actions = testcase.get("teardown", [])
|
||||
|
||||
@@ -157,7 +158,7 @@ class Runner(object):
|
||||
"variables": [], # optional, override
|
||||
"request": {},
|
||||
"extract": {}, # optional
|
||||
"validators": {} # optional
|
||||
"validate": {} # optional
|
||||
},
|
||||
testcase12
|
||||
]
|
||||
|
||||
@@ -24,7 +24,7 @@ Suppose we get the following HTTP response.
|
||||
}
|
||||
```
|
||||
|
||||
In `extract` and `validators`, we can do chain operation to extract data field in HTTP response.
|
||||
In `extract` and `validate`, we can do chain operation to extract data field in HTTP response.
|
||||
|
||||
For instance, if we want to get `Content-Type` in response headers, then we can specify `headers.content-type`; if we want to get `first_name` in response content, we can specify `content.person.name.first_name`.
|
||||
|
||||
@@ -49,7 +49,7 @@ content.person.cities.1
|
||||
extract:
|
||||
- content_type: headers.content-type
|
||||
- first_name: content.person.name.first_name
|
||||
validators:
|
||||
validate:
|
||||
- {"check": "status_code", "comparator": "eq", "expected": 200}
|
||||
- {"check": "headers.content-type", "expected": "application/json"}
|
||||
- {"check": "headers.content-length", "comparator": "gt", "expected": 40}
|
||||
|
||||
@@ -65,7 +65,7 @@ Open your favorite text editor and you can write test cases like this.
|
||||
json:
|
||||
name: "user1"
|
||||
password: "123456"
|
||||
validators:
|
||||
validate:
|
||||
- {"check": "status_code", "comparator": "eq", "expected": 201}
|
||||
- {"check": "content.success", "comparator": "eq", "expected": true}
|
||||
```
|
||||
@@ -122,7 +122,7 @@ To fix this problem, we should correlate `token` field in the second API test ca
|
||||
sign: 19067cf712265eb5426db8d3664026c1ccea02b9
|
||||
extract:
|
||||
- token: content.token
|
||||
validators:
|
||||
validate:
|
||||
- {"check": "status_code", "comparator": "eq", "expected": 200}
|
||||
- {"check": "content.token", "comparator": "len_eq", "expected": 16}
|
||||
|
||||
@@ -137,7 +137,7 @@ To fix this problem, we should correlate `token` field in the second API test ca
|
||||
json:
|
||||
name: "user1"
|
||||
password: "123456"
|
||||
validators:
|
||||
validate:
|
||||
- {"check": "status_code", "comparator": "eq", "expected": 201}
|
||||
- {"check": "content.success", "comparator": "eq", "expected": true}
|
||||
```
|
||||
@@ -204,7 +204,7 @@ And then, we can revise our demo test case and reference the functions. Suppose
|
||||
sign: ${get_sign($user_agent, $device_sn, $os_platform, $app_version)}
|
||||
extract:
|
||||
- token: content.token
|
||||
validators:
|
||||
validate:
|
||||
- {"check": "status_code", "comparator": "eq", "expected": 200}
|
||||
- {"check": "content.token", "comparator": "len_eq", "expected": 16}
|
||||
|
||||
@@ -219,7 +219,7 @@ And then, we can revise our demo test case and reference the functions. Suppose
|
||||
json:
|
||||
name: "user1"
|
||||
password: "123456"
|
||||
validators:
|
||||
validate:
|
||||
- {"check": "status_code", "comparator": "eq", "expected": 201}
|
||||
- {"check": "content.success", "comparator": "eq", "expected": true}
|
||||
```
|
||||
@@ -268,7 +268,7 @@ To handle this case, overall `config` block is supported in `ApiTestEngine`. If
|
||||
sign: ${get_sign($user_agent, $device_sn, $os_platform, $app_version)}
|
||||
extract:
|
||||
- token: content.token
|
||||
validators:
|
||||
validate:
|
||||
- {"check": "status_code", "comparator": "eq", "expected": 200}
|
||||
- {"check": "content.token", "comparator": "len_eq", "expected": 16}
|
||||
|
||||
@@ -282,7 +282,7 @@ To handle this case, overall `config` block is supported in `ApiTestEngine`. If
|
||||
json:
|
||||
name: "user1"
|
||||
password: "123456"
|
||||
validators:
|
||||
validate:
|
||||
- {"check": "status_code", "comparator": "eq", "expected": 201}
|
||||
- {"check": "content.success", "comparator": "eq", "expected": true}
|
||||
```
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
app_version: 2.8.6
|
||||
json:
|
||||
sign: 19067cf712265eb5426db8d3664026c1ccea02b9
|
||||
validators:
|
||||
validate:
|
||||
- {"check": "status_code", "comparator": "eq", "expected": 200}
|
||||
- {"check": "content.token", "comparator": "len_eq", "expected": 16}
|
||||
|
||||
@@ -25,6 +25,6 @@
|
||||
json:
|
||||
name: "user1"
|
||||
password: "123456"
|
||||
validators:
|
||||
validate:
|
||||
- {"check": "status_code", "comparator": "eq", "expected": 201}
|
||||
- {"check": "content.success", "comparator": "eq", "expected": true}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
sign: 19067cf712265eb5426db8d3664026c1ccea02b9
|
||||
extract:
|
||||
- token: content.token
|
||||
validators:
|
||||
validate:
|
||||
- {"check": "status_code", "comparator": "eq", "expected": 200}
|
||||
- {"check": "content.token", "comparator": "len_eq", "expected": 16}
|
||||
|
||||
@@ -27,6 +27,6 @@
|
||||
json:
|
||||
name: "user1"
|
||||
password: "123456"
|
||||
validators:
|
||||
validate:
|
||||
- {"check": "status_code", "comparator": "eq", "expected": 201}
|
||||
- {"check": "content.success", "comparator": "eq", "expected": true}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
sign: ${get_sign($user_agent, $device_sn, $os_platform, $app_version)}
|
||||
extract:
|
||||
- token: content.token
|
||||
validators:
|
||||
validate:
|
||||
- {"check": "status_code", "comparator": "eq", "expected": 200}
|
||||
- {"check": "content.token", "comparator": "len_eq", "expected": 16}
|
||||
|
||||
@@ -32,6 +32,6 @@
|
||||
json:
|
||||
name: "user1"
|
||||
password: "123456"
|
||||
validators:
|
||||
validate:
|
||||
- {"check": "status_code", "comparator": "eq", "expected": 201}
|
||||
- {"check": "content.success", "comparator": "eq", "expected": true}
|
||||
@@ -24,7 +24,7 @@
|
||||
sign: ${get_sign($user_agent, $device_sn, $os_platform, $app_version)}
|
||||
extract:
|
||||
- token: content.token
|
||||
validators:
|
||||
validate:
|
||||
- {"check": "status_code", "comparator": "eq", "expected": 200}
|
||||
- {"check": "content.token", "comparator": "len_eq", "expected": 16}
|
||||
|
||||
@@ -38,6 +38,6 @@
|
||||
json:
|
||||
name: "user1"
|
||||
password: "123456"
|
||||
validators:
|
||||
validate:
|
||||
- {"check": "status_code", "comparator": "eq", "expected": 201}
|
||||
- {"check": "content.success", "comparator": "eq", "expected": true}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
app_version: $app_version
|
||||
json:
|
||||
sign: ${get_sign($user_agent, $device_sn, $os_platform, $app_version)}
|
||||
validators:
|
||||
validate:
|
||||
- {"check": "status_code", "comparator": "eq", "expected": 200}
|
||||
- {"check": "content.token", "comparator": "len_eq", "expected": 16}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
"token": "content.token"
|
||||
}
|
||||
],
|
||||
"validators": [
|
||||
"validate": [
|
||||
{"check": "status_code", "comparator": "eq", "expected": 200},
|
||||
{"check": "content.token", "comparator": "len_eq", "expected": 16}
|
||||
]
|
||||
@@ -43,7 +43,7 @@
|
||||
"password": "123456"
|
||||
}
|
||||
},
|
||||
"validators": [
|
||||
"validate": [
|
||||
{"check": "status_code", "comparator": "eq", "expected": 201},
|
||||
{"check": "content.success", "comparator": "eq", "expected": true}
|
||||
]
|
||||
@@ -65,7 +65,7 @@
|
||||
"password": "123456"
|
||||
}
|
||||
},
|
||||
"validators": [
|
||||
"validate": [
|
||||
{"check": "status_code", "comparator": "eq", "expected": 500},
|
||||
{"check": "content.success", "comparator": "eq", "expected": false}
|
||||
]
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
sign: f1219719911caae89ccc301679857ebfda115ca2
|
||||
extract:
|
||||
- token: content.token
|
||||
validators:
|
||||
validate:
|
||||
- {"check": "status_code", "comparator": "eq", "expected": 200}
|
||||
- {"check": "content.token", "comparator": "len_eq", "expected": 16}
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
json:
|
||||
name: "user1"
|
||||
password: "123456"
|
||||
validators:
|
||||
validate:
|
||||
- {"check": "status_code", "comparator": "eq", "expected": 201}
|
||||
- {"check": "content.success", "comparator": "eq", "expected": true}
|
||||
|
||||
@@ -45,6 +45,6 @@
|
||||
json:
|
||||
name: "user1"
|
||||
password: "123456"
|
||||
validators:
|
||||
validate:
|
||||
- {"check": "status_code", "comparator": "eq", "expected": 500}
|
||||
- {"check": "content.success", "comparator": "eq", "expected": false}
|
||||
@@ -22,14 +22,14 @@
|
||||
- test:
|
||||
name: reset all users
|
||||
api: reset_all($token)
|
||||
validators:
|
||||
validate:
|
||||
- {"check": "status_code", "expected": 200}
|
||||
- {"check": "content.success", "expected": true}
|
||||
|
||||
- test:
|
||||
name: get user that does not exist
|
||||
api: get_user(1000, $token)
|
||||
validators:
|
||||
validate:
|
||||
- {"check": "status_code", "expected": 404}
|
||||
- {"check": "content.success", "expected": false}
|
||||
|
||||
@@ -39,14 +39,14 @@
|
||||
- user_name: "user1"
|
||||
- user_password: "123456"
|
||||
api: create_user(1000, $user_name, $user_password, $token)
|
||||
validators:
|
||||
validate:
|
||||
- {"check": "status_code", "expected": 201}
|
||||
- {"check": "content.success", "expected": true}
|
||||
|
||||
- test:
|
||||
name: get user that has been created
|
||||
api: get_user(1000, $token)
|
||||
validators:
|
||||
validate:
|
||||
- {"check": "status_code", "expected": 200}
|
||||
- {"check": "content.success", "expected": true}
|
||||
- {"check": "content.data.password", "expected": "123456"}
|
||||
@@ -57,7 +57,7 @@
|
||||
- user_name: "user1"
|
||||
- user_password: "123456"
|
||||
api: create_user(1000, $user_name, $user_password, $token)
|
||||
validators:
|
||||
validate:
|
||||
- {"check": "status_code", "expected": 500}
|
||||
- {"check": "content.success", "expected": false}
|
||||
|
||||
@@ -67,14 +67,14 @@
|
||||
- user_name: "user1"
|
||||
- user_password: "654321"
|
||||
api: update_user(1000, $user_name, $user_password, $token)
|
||||
validators:
|
||||
validate:
|
||||
- {"check": "status_code", "expected": 200}
|
||||
- {"check": "content.success", "expected": true}
|
||||
|
||||
- test:
|
||||
name: get user that has been updated
|
||||
api: get_user(1000, $token)
|
||||
validators:
|
||||
validate:
|
||||
- {"check": "status_code", "expected": 200}
|
||||
- {"check": "content.success", "expected": true}
|
||||
- {"check": "content.data.password", "expected": "654321"}
|
||||
@@ -82,21 +82,21 @@
|
||||
- test:
|
||||
name: get users
|
||||
api: get_users($token)
|
||||
validators:
|
||||
validate:
|
||||
- {"check": "status_code", "expected": 200}
|
||||
- {"check": "content.count", "expected": 1}
|
||||
|
||||
- test:
|
||||
name: delete user that exists
|
||||
api: delete_user(1000, $token)
|
||||
validators:
|
||||
validate:
|
||||
- {"check": "status_code", "expected": 200}
|
||||
- {"check": "content.success", "expected": true}
|
||||
|
||||
- test:
|
||||
name: get users
|
||||
api: get_users($token)
|
||||
validators:
|
||||
validate:
|
||||
- {"check": "status_code", "expected": 200}
|
||||
- {"check": "content.count", "expected": 0}
|
||||
|
||||
@@ -106,13 +106,13 @@
|
||||
- user_name: "user1"
|
||||
- user_password: "123456"
|
||||
api: create_user(1000, $user_name, $user_password, $token)
|
||||
validators:
|
||||
validate:
|
||||
- {"check": "status_code", "expected": 201}
|
||||
- {"check": "content.success", "expected": true}
|
||||
|
||||
- test:
|
||||
name: get users
|
||||
api: get_users($token)
|
||||
validators:
|
||||
validate:
|
||||
- {"check": "status_code", "expected": 200}
|
||||
- {"check": "content.count", "expected": 1}
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
sign: ${get_sign($user_agent, $device_sn, $os_platform, $app_version)}
|
||||
extract:
|
||||
- token: content.token
|
||||
validators:
|
||||
validate:
|
||||
- {"check": "status_code", "comparator": "eq", "expected": 200}
|
||||
- {"check": "content.token", "comparator": "len_eq", "expected": 16}
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
json:
|
||||
name: $user_name
|
||||
password: $user_password
|
||||
validators:
|
||||
validate:
|
||||
- {"check": "status_code", "comparator": "eq", "expected": 201}
|
||||
- {"check": "content.success", "comparator": "eq", "expected": true}
|
||||
|
||||
@@ -58,6 +58,6 @@
|
||||
json:
|
||||
name: "user1"
|
||||
password: "123456"
|
||||
validators:
|
||||
validate:
|
||||
- {"check": "status_code", "comparator": "eq", "expected": 500}
|
||||
- {"check": "content.success", "comparator": "eq", "expected": false}
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
sign: ${get_sign_lambda($user_agent, $device_sn, $os_platform, $app_version)}
|
||||
extract:
|
||||
- token: content.token
|
||||
validators:
|
||||
validate:
|
||||
- {"check": "status_code", "comparator": "eq", "expected": 200}
|
||||
- {"check": "content.token", "comparator": "len_eq", "expected": 16}
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
json:
|
||||
name: $user_name
|
||||
password: $user_password
|
||||
validators:
|
||||
validate:
|
||||
- {"check": "status_code", "comparator": "eq", "expected": 201}
|
||||
- {"check": "content.success", "comparator": "eq", "expected": true}
|
||||
|
||||
@@ -68,6 +68,6 @@
|
||||
json:
|
||||
name: "user1"
|
||||
password: "123456"
|
||||
validators:
|
||||
validate:
|
||||
- {"check": "status_code", "comparator": "eq", "expected": 500}
|
||||
- {"check": "content.success", "comparator": "eq", "expected": false}
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
sign: $sign
|
||||
extract:
|
||||
- token: content.token
|
||||
validators:
|
||||
validate:
|
||||
- {"check": "status_code", "comparator": "eq", "expected": 200}
|
||||
- {"check": "content.token", "comparator": "len_eq", "expected": 16}
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
json:
|
||||
name: $user_name
|
||||
password: $user_password
|
||||
validators:
|
||||
validate:
|
||||
- {"check": "status_code", "comparator": "eq", "expected": 201}
|
||||
- {"check": "content.success", "comparator": "eq", "expected": true}
|
||||
|
||||
@@ -59,6 +59,6 @@
|
||||
json:
|
||||
name: "user1"
|
||||
password: "123456"
|
||||
validators:
|
||||
validate:
|
||||
- {"check": "status_code", "comparator": "eq", "expected": 500}
|
||||
- {"check": "content.success", "comparator": "eq", "expected": false}
|
||||
|
||||
@@ -56,7 +56,7 @@ class TestRunner(ApiServerUnittest):
|
||||
"extract": [
|
||||
{"token": "content.token"}
|
||||
],
|
||||
"validators": [
|
||||
"validate": [
|
||||
{"check": "status_code", "comparator": "eq", "expected": 205},
|
||||
{"check": "content.token", "comparator": "len_eq", "expected": 19}
|
||||
]
|
||||
|
||||
@@ -421,7 +421,7 @@ class TestcaseParserUnittest(unittest.TestCase):
|
||||
self.assertIn("request", testsets_list[0]["config"])
|
||||
self.assertIn("request", testsets_list[0]["testcases"][0])
|
||||
self.assertIn("url", testsets_list[0]["testcases"][0]["request"])
|
||||
self.assertIn("validators", testsets_list[0]["testcases"][0])
|
||||
self.assertIn("validate", testsets_list[0]["testcases"][0])
|
||||
|
||||
def test_substitute_variables_with_mapping(self):
|
||||
content = {
|
||||
|
||||
Reference in New Issue
Block a user