From c6f41b84e6c961d83caf6aa219111f14ab2bd2e9 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Thu, 4 Apr 2019 15:36:58 +0800 Subject: [PATCH] fix unittest --- tests/api/get_token.yml | 2 +- tests/api_server.py | 4 +--- tests/base.py | 2 +- tests/data/demo_testcase_cli.yml | 2 +- tests/data/demo_testcase_functions.yml | 2 +- tests/data/demo_testcase_hardcode.json | 2 +- tests/data/demo_testcase_hardcode.yml | 2 +- tests/data/demo_testcase_variables.yml | 2 +- tests/test_api.py | 5 +++-- tests/test_parser.py | 2 +- tests/test_runner.py | 12 ++++++------ 11 files changed, 18 insertions(+), 19 deletions(-) diff --git a/tests/api/get_token.yml b/tests/api/get_token.yml index 9444fb9e..24a028bc 100644 --- a/tests/api/get_token.yml +++ b/tests/api/get_token.yml @@ -15,7 +15,7 @@ request: Content-Type: "application/json" device_sn: $device_sn json: - sign: ${get_sign($user_agent, $device_sn, $os_platform, $app_version)} + sign: ${get_sign($device_sn, $os_platform, $app_version)} validate: - eq: ["status_code", 0] - len_eq: ["content.token", 12] diff --git a/tests/api_server.py b/tests/api_server.py index baadc949..0b20c5d9 100644 --- a/tests/api_server.py +++ b/tests/api_server.py @@ -93,15 +93,13 @@ def index(): @app.route('/api/get-token', methods=['POST']) def get_token(): - user_agent = request.headers.get('User-Agent', "") device_sn = request.headers.get('device_sn', "") os_platform = request.headers.get('os_platform', "") app_version = request.headers.get('app_version', "") data = request.get_json() 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: result = { 'success': False, diff --git a/tests/base.py b/tests/base.py index 8c6c5abc..82198842 100644 --- a/tests/base.py +++ b/tests/base.py @@ -50,7 +50,7 @@ class ApiServerUnittest(unittest.TestCase): 'app_version': app_version } 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) diff --git a/tests/data/demo_testcase_cli.yml b/tests/data/demo_testcase_cli.yml index 56cb0ef3..27db9390 100644 --- a/tests/data/demo_testcase_cli.yml +++ b/tests/data/demo_testcase_cli.yml @@ -10,7 +10,7 @@ os_platform: 'ios' app_version: '2.8.6' json: - sign: f1219719911caae89ccc301679857ebfda115ca2 + sign: 5188962c489d1a35effa99e9346dd5efd4fdabad variables: expect_status_code: 200 token_len: 16 diff --git a/tests/data/demo_testcase_functions.yml b/tests/data/demo_testcase_functions.yml index 43b1c55f..801b618b 100644 --- a/tests/data/demo_testcase_functions.yml +++ b/tests/data/demo_testcase_functions.yml @@ -18,7 +18,7 @@ os_platform: $os_platform app_version: $app_version json: - sign: ${get_sign($user_agent, $device_sn, $os_platform, $app_version)} + sign: ${get_sign($device_sn, $os_platform, $app_version)} extract: - token: content.token validate: diff --git a/tests/data/demo_testcase_hardcode.json b/tests/data/demo_testcase_hardcode.json index 690058f9..efe42738 100644 --- a/tests/data/demo_testcase_hardcode.json +++ b/tests/data/demo_testcase_hardcode.json @@ -13,7 +13,7 @@ "app_version": "2.8.6" }, "json": { - "sign": "f1219719911caae89ccc301679857ebfda115ca2" + "sign": "5188962c489d1a35effa99e9346dd5efd4fdabad" } }, "variables": [ diff --git a/tests/data/demo_testcase_hardcode.yml b/tests/data/demo_testcase_hardcode.yml index 004d2ac2..05df6b4a 100644 --- a/tests/data/demo_testcase_hardcode.yml +++ b/tests/data/demo_testcase_hardcode.yml @@ -10,7 +10,7 @@ os_platform: 'ios' app_version: '2.8.6' json: - sign: f1219719911caae89ccc301679857ebfda115ca2 + sign: 5188962c489d1a35effa99e9346dd5efd4fdabad variables: expect_status_code: 200 token_len: 16 diff --git a/tests/data/demo_testcase_variables.yml b/tests/data/demo_testcase_variables.yml index 3119b1fa..2510d514 100644 --- a/tests/data/demo_testcase_variables.yml +++ b/tests/data/demo_testcase_variables.yml @@ -10,7 +10,7 @@ user_agent: 'iOS/10.3' os_platform: 'ios' app_version: '2.8.6' - sign: f1219719911caae89ccc301679857ebfda115ca2 + sign: 5188962c489d1a35effa99e9346dd5efd4fdabad request: url: /api/get-token method: POST diff --git a/tests/test_api.py b/tests/test_api.py index f4f111b2..b969944e 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -36,7 +36,7 @@ class TestHttpRunner(ApiServerUnittest): 'url': 'http://127.0.0.1:5000/api/get-token', 'method': 'POST', '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': [ {'token': 'content.token'} @@ -52,7 +52,8 @@ class TestHttpRunner(ApiServerUnittest): 'request': { 'url': 'http://127.0.0.1:5000/api/users/1000', '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': [ {'eq': ['status_code', 201]}, diff --git a/tests/test_parser.py b/tests/test_parser.py index 9fe6c266..cf996648 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -1073,7 +1073,7 @@ class TestParser(unittest.TestCase): 'url': '/api/get-token', 'method': 'POST', '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': [ {'eq': ['status_code', 201]}, diff --git a/tests/test_runner.py b/tests/test_runner.py index b4f6115f..a952406f 100644 --- a/tests/test_runner.py +++ b/tests/test_runner.py @@ -68,7 +68,7 @@ class TestRunner(ApiServerUnittest): "app_version": "2.8.6" }, "json": { - "sign": "f1219719911caae89ccc301679857ebfda115ca2" + "sign": "5188962c489d1a35effa99e9346dd5efd4fdabad" } }, "validate": [ @@ -115,7 +115,7 @@ class TestRunner(ApiServerUnittest): "app_version": "2.8.6" }, "json": { - "sign": "f1219719911caae89ccc301679857ebfda115ca2" + "sign": "5188962c489d1a35effa99e9346dd5efd4fdabad" } }, "validate": [ @@ -176,7 +176,7 @@ class TestRunner(ApiServerUnittest): }, "json": { "os_platform": "ios", - "sign": "f1219719911caae89ccc301679857ebfda115ca2" + "sign": "5188962c489d1a35effa99e9346dd5efd4fdabad" } }, "setup_hooks": [ @@ -205,7 +205,7 @@ class TestRunner(ApiServerUnittest): "app_version": "2.8.6" }, "json": { - "sign": "f1219719911caae89ccc301679857ebfda115ca2" + "sign": "5188962c489d1a35effa99e9346dd5efd4fdabad" } }, "validate": [ @@ -233,7 +233,7 @@ class TestRunner(ApiServerUnittest): "app_version": "2.8.6" }, "json": { - "sign": "f1219719911caae89ccc301679857ebfda115ca2" + "sign": "5188962c489d1a35effa99e9346dd5efd4fdabad" } }, "validate": [ @@ -270,7 +270,7 @@ class TestRunner(ApiServerUnittest): "app_version": "2.8.6" }, "json": { - "sign": "f1219719911caae89ccc301679857ebfda115ca2" + "sign": "5188962c489d1a35effa99e9346dd5efd4fdabad" } }, "validate": [