mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 07:26:55 +08:00
fix unittest
This commit is contained in:
@@ -15,7 +15,7 @@ request:
|
|||||||
Content-Type: "application/json"
|
Content-Type: "application/json"
|
||||||
device_sn: $device_sn
|
device_sn: $device_sn
|
||||||
json:
|
json:
|
||||||
sign: ${get_sign($user_agent, $device_sn, $os_platform, $app_version)}
|
sign: ${get_sign($device_sn, $os_platform, $app_version)}
|
||||||
validate:
|
validate:
|
||||||
- eq: ["status_code", 0]
|
- eq: ["status_code", 0]
|
||||||
- len_eq: ["content.token", 12]
|
- len_eq: ["content.token", 12]
|
||||||
|
|||||||
+1
-3
@@ -93,15 +93,13 @@ def index():
|
|||||||
|
|
||||||
@app.route('/api/get-token', methods=['POST'])
|
@app.route('/api/get-token', methods=['POST'])
|
||||||
def get_token():
|
def get_token():
|
||||||
user_agent = request.headers.get('User-Agent', "")
|
|
||||||
device_sn = request.headers.get('device_sn', "")
|
device_sn = request.headers.get('device_sn', "")
|
||||||
os_platform = request.headers.get('os_platform', "")
|
os_platform = request.headers.get('os_platform', "")
|
||||||
app_version = request.headers.get('app_version', "")
|
app_version = request.headers.get('app_version', "")
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
sign = data.get('sign', "")
|
sign = data.get('sign', "")
|
||||||
|
|
||||||
expected_sign = get_sign(user_agent, device_sn, os_platform, app_version)
|
expected_sign = get_sign(device_sn, os_platform, app_version)
|
||||||
|
|
||||||
if expected_sign != sign:
|
if expected_sign != sign:
|
||||||
result = {
|
result = {
|
||||||
'success': False,
|
'success': False,
|
||||||
|
|||||||
+1
-1
@@ -50,7 +50,7 @@ class ApiServerUnittest(unittest.TestCase):
|
|||||||
'app_version': app_version
|
'app_version': app_version
|
||||||
}
|
}
|
||||||
data = {
|
data = {
|
||||||
'sign': get_sign(user_agent, device_sn, os_platform, app_version)
|
'sign': get_sign(device_sn, os_platform, app_version)
|
||||||
}
|
}
|
||||||
|
|
||||||
resp = self.api_client.post(url, json=data, headers=headers)
|
resp = self.api_client.post(url, json=data, headers=headers)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
os_platform: 'ios'
|
os_platform: 'ios'
|
||||||
app_version: '2.8.6'
|
app_version: '2.8.6'
|
||||||
json:
|
json:
|
||||||
sign: f1219719911caae89ccc301679857ebfda115ca2
|
sign: 5188962c489d1a35effa99e9346dd5efd4fdabad
|
||||||
variables:
|
variables:
|
||||||
expect_status_code: 200
|
expect_status_code: 200
|
||||||
token_len: 16
|
token_len: 16
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
os_platform: $os_platform
|
os_platform: $os_platform
|
||||||
app_version: $app_version
|
app_version: $app_version
|
||||||
json:
|
json:
|
||||||
sign: ${get_sign($user_agent, $device_sn, $os_platform, $app_version)}
|
sign: ${get_sign($device_sn, $os_platform, $app_version)}
|
||||||
extract:
|
extract:
|
||||||
- token: content.token
|
- token: content.token
|
||||||
validate:
|
validate:
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
"app_version": "2.8.6"
|
"app_version": "2.8.6"
|
||||||
},
|
},
|
||||||
"json": {
|
"json": {
|
||||||
"sign": "f1219719911caae89ccc301679857ebfda115ca2"
|
"sign": "5188962c489d1a35effa99e9346dd5efd4fdabad"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"variables": [
|
"variables": [
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
os_platform: 'ios'
|
os_platform: 'ios'
|
||||||
app_version: '2.8.6'
|
app_version: '2.8.6'
|
||||||
json:
|
json:
|
||||||
sign: f1219719911caae89ccc301679857ebfda115ca2
|
sign: 5188962c489d1a35effa99e9346dd5efd4fdabad
|
||||||
variables:
|
variables:
|
||||||
expect_status_code: 200
|
expect_status_code: 200
|
||||||
token_len: 16
|
token_len: 16
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
user_agent: 'iOS/10.3'
|
user_agent: 'iOS/10.3'
|
||||||
os_platform: 'ios'
|
os_platform: 'ios'
|
||||||
app_version: '2.8.6'
|
app_version: '2.8.6'
|
||||||
sign: f1219719911caae89ccc301679857ebfda115ca2
|
sign: 5188962c489d1a35effa99e9346dd5efd4fdabad
|
||||||
request:
|
request:
|
||||||
url: /api/get-token
|
url: /api/get-token
|
||||||
method: POST
|
method: POST
|
||||||
|
|||||||
+3
-2
@@ -36,7 +36,7 @@ class TestHttpRunner(ApiServerUnittest):
|
|||||||
'url': 'http://127.0.0.1:5000/api/get-token',
|
'url': 'http://127.0.0.1:5000/api/get-token',
|
||||||
'method': 'POST',
|
'method': 'POST',
|
||||||
'headers': {'Content-Type': 'application/json', 'app_version': '2.8.6', 'device_sn': 'FwgRiO7CNA50DSU', 'os_platform': 'ios', 'user_agent': 'iOS/10.3'},
|
'headers': {'Content-Type': 'application/json', 'app_version': '2.8.6', 'device_sn': 'FwgRiO7CNA50DSU', 'os_platform': 'ios', 'user_agent': 'iOS/10.3'},
|
||||||
'json': {'sign': '958a05393efef0ac7c0fb80a7eac45e24fd40c27'}
|
'json': {'sign': '9c0c7e51c91ae963c833a4ccbab8d683c4a90c98'}
|
||||||
},
|
},
|
||||||
'extract': [
|
'extract': [
|
||||||
{'token': 'content.token'}
|
{'token': 'content.token'}
|
||||||
@@ -52,7 +52,8 @@ class TestHttpRunner(ApiServerUnittest):
|
|||||||
'request': {
|
'request': {
|
||||||
'url': 'http://127.0.0.1:5000/api/users/1000',
|
'url': 'http://127.0.0.1:5000/api/users/1000',
|
||||||
'method': 'POST',
|
'method': 'POST',
|
||||||
'headers': {'Content-Type': 'application/json', 'device_sn': 'FwgRiO7CNA50DSU','token': '$token'}, 'json': {'name': 'user1', 'password': '123456'}
|
'headers': {'Content-Type': 'application/json', 'device_sn': 'FwgRiO7CNA50DSU','token': '$token'},
|
||||||
|
'json': {'name': 'user1', 'password': '123456'}
|
||||||
},
|
},
|
||||||
'validate': [
|
'validate': [
|
||||||
{'eq': ['status_code', 201]},
|
{'eq': ['status_code', 201]},
|
||||||
|
|||||||
@@ -1073,7 +1073,7 @@ class TestParser(unittest.TestCase):
|
|||||||
'url': '/api/get-token',
|
'url': '/api/get-token',
|
||||||
'method': 'POST',
|
'method': 'POST',
|
||||||
'headers': {'user_agent': '$user_agent', 'device_sn': '$device_sn', 'os_platform': '$os_platform', 'app_version': '$app_version'},
|
'headers': {'user_agent': '$user_agent', 'device_sn': '$device_sn', 'os_platform': '$os_platform', 'app_version': '$app_version'},
|
||||||
'json': {'sign': '${get_sign($user_agent, $device_sn, $os_platform, $app_version)}'}
|
'json': {'sign': '${get_sign($device_sn, $os_platform, $app_version)}'}
|
||||||
},
|
},
|
||||||
'validate': [
|
'validate': [
|
||||||
{'eq': ['status_code', 201]},
|
{'eq': ['status_code', 201]},
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ class TestRunner(ApiServerUnittest):
|
|||||||
"app_version": "2.8.6"
|
"app_version": "2.8.6"
|
||||||
},
|
},
|
||||||
"json": {
|
"json": {
|
||||||
"sign": "f1219719911caae89ccc301679857ebfda115ca2"
|
"sign": "5188962c489d1a35effa99e9346dd5efd4fdabad"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"validate": [
|
"validate": [
|
||||||
@@ -115,7 +115,7 @@ class TestRunner(ApiServerUnittest):
|
|||||||
"app_version": "2.8.6"
|
"app_version": "2.8.6"
|
||||||
},
|
},
|
||||||
"json": {
|
"json": {
|
||||||
"sign": "f1219719911caae89ccc301679857ebfda115ca2"
|
"sign": "5188962c489d1a35effa99e9346dd5efd4fdabad"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"validate": [
|
"validate": [
|
||||||
@@ -176,7 +176,7 @@ class TestRunner(ApiServerUnittest):
|
|||||||
},
|
},
|
||||||
"json": {
|
"json": {
|
||||||
"os_platform": "ios",
|
"os_platform": "ios",
|
||||||
"sign": "f1219719911caae89ccc301679857ebfda115ca2"
|
"sign": "5188962c489d1a35effa99e9346dd5efd4fdabad"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"setup_hooks": [
|
"setup_hooks": [
|
||||||
@@ -205,7 +205,7 @@ class TestRunner(ApiServerUnittest):
|
|||||||
"app_version": "2.8.6"
|
"app_version": "2.8.6"
|
||||||
},
|
},
|
||||||
"json": {
|
"json": {
|
||||||
"sign": "f1219719911caae89ccc301679857ebfda115ca2"
|
"sign": "5188962c489d1a35effa99e9346dd5efd4fdabad"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"validate": [
|
"validate": [
|
||||||
@@ -233,7 +233,7 @@ class TestRunner(ApiServerUnittest):
|
|||||||
"app_version": "2.8.6"
|
"app_version": "2.8.6"
|
||||||
},
|
},
|
||||||
"json": {
|
"json": {
|
||||||
"sign": "f1219719911caae89ccc301679857ebfda115ca2"
|
"sign": "5188962c489d1a35effa99e9346dd5efd4fdabad"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"validate": [
|
"validate": [
|
||||||
@@ -270,7 +270,7 @@ class TestRunner(ApiServerUnittest):
|
|||||||
"app_version": "2.8.6"
|
"app_version": "2.8.6"
|
||||||
},
|
},
|
||||||
"json": {
|
"json": {
|
||||||
"sign": "f1219719911caae89ccc301679857ebfda115ca2"
|
"sign": "5188962c489d1a35effa99e9346dd5efd4fdabad"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"validate": [
|
"validate": [
|
||||||
|
|||||||
Reference in New Issue
Block a user