From 708d26ee83adfdb24c90e360e835ac8091f43593 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Wed, 20 Feb 2019 11:51:30 +0800 Subject: [PATCH 1/3] update modify_request_json --- tests/debugtalk.py | 4 ++-- tests/test_runner.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/debugtalk.py b/tests/debugtalk.py index 87a7ee8b..74b9a3d3 100644 --- a/tests/debugtalk.py +++ b/tests/debugtalk.py @@ -89,8 +89,8 @@ def teardown_hook_sleep_N_secs(response, n_secs): def hook_print(msg): print(msg) -def modify_headers_os_platform(request, os_platform): - request["headers"]["os_platform"] = os_platform +def modify_request_json(request, os_platform): + request["json"]["os_platform"] = os_platform def setup_hook_httpntlmauth(request): if "httpntlmauth" in request: diff --git a/tests/test_runner.py b/tests/test_runner.py index 5917205f..38d5f508 100644 --- a/tests/test_runner.py +++ b/tests/test_runner.py @@ -164,19 +164,19 @@ class TestRunner(ApiServerUnittest): "method": "POST", "headers": { "content-type": "application/json", - "user_agent": "iOS/10.3", - "os_platform": "ios" + "user_agent": "iOS/10.3" }, "json": { + "os_platform": "ios", "sign": "f1219719911caae89ccc301679857ebfda115ca2" } }, "setup_hooks": [ - "${modify_headers_os_platform($request, android)}" + "${modify_request_json($request, android)}" ], "validate": [ {"check": "status_code", "expect": 200}, - {"check": "content.headers.Os-Platform", "expect": "android"} + {"check": "content.json.os_platform", "expect": "android"} ] } test_runner = runner.Runner(config_dict, self.debugtalk_functions) From 9c0bbbd248fa2eac998ec732c854553551f29a3f Mon Sep 17 00:00:00 2001 From: debugtalk Date: Wed, 20 Feb 2019 11:53:04 +0800 Subject: [PATCH 2/3] bugfix: dump file with Chinese charactor in Python 3 --- httprunner/utils.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/httprunner/utils.py b/httprunner/utils.py index 88eecacd..79d7d130 100644 --- a/httprunner/utils.py +++ b/httprunner/utils.py @@ -661,7 +661,13 @@ def dump_json_file(json_data, pwd_dir_path, dump_file_name): )) ) else: - json.dump(json_data, outfile, indent=4, separators=(',', ':')) + json.dump( + json_data, + outfile, + indent=4, + separators=(',', ':'), + ensure_ascii=False + ) msg = "dump file: {}".format(dump_file_path) logger.color_print(msg, "BLUE") From ccef209a14502e235d7c399ed3a36a84f1967261 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Wed, 20 Feb 2019 11:57:18 +0800 Subject: [PATCH 3/3] bugfix: Chinese charactor in log_file encoding error in Windows --- httprunner/logger.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/httprunner/logger.py b/httprunner/logger.py index eb7cab02..3aab4937 100644 --- a/httprunner/logger.py +++ b/httprunner/logger.py @@ -37,7 +37,7 @@ def setup_logger(log_level, log_file=None): ) if log_file: - handler = logging.FileHandler(log_file) + handler = logging.FileHandler(log_file, encoding="utf-8") else: handler = logging.StreamHandler()