mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
增加#430修复代码测试案例
This commit is contained in:
@@ -127,6 +127,15 @@ def alter_response(response):
|
||||
"key": 123
|
||||
}
|
||||
|
||||
def alter_response_302(response):
|
||||
response.status_code = 500
|
||||
response.headers["Content-Type"] = "html/text"
|
||||
response.text = "abcdef"
|
||||
response.new_attribute = "new_attribute_value"
|
||||
response.new_attribute_dict = {
|
||||
"key": 123
|
||||
}
|
||||
|
||||
|
||||
def alter_response_error(response):
|
||||
# NameError
|
||||
|
||||
13
tests/httpbin/api/302_redirect_teardown_hook.yml
Normal file
13
tests/httpbin/api/302_redirect_teardown_hook.yml
Normal file
@@ -0,0 +1,13 @@
|
||||
name: 302 redirect
|
||||
request:
|
||||
url: https://httpbin.org/redirect-to
|
||||
params:
|
||||
url: https://github.com
|
||||
status_code: 302
|
||||
method: GET
|
||||
verify: False
|
||||
teardown_hooks:
|
||||
- ${alter_response_302($response)}
|
||||
validate:
|
||||
- eq: ["status_code", 500]
|
||||
- eq: ["text","abcdef"]
|
||||
@@ -419,6 +419,19 @@ class TestHttpRunner(ApiServerUnittest):
|
||||
self.assertEqual(req_resp_data[0]["response"]["status_code"], 302)
|
||||
self.assertEqual(req_resp_data[1]["response"]["status_code"], 200)
|
||||
|
||||
def test_request_302_logs_teardown_hook(self):
|
||||
path = "tests/httpbin/api/302_redirect_teardown_hook.yml"
|
||||
summary = self.runner.run(path)
|
||||
self.assertTrue(summary["success"])
|
||||
self.assertEqual(summary["stat"]["testcases"]["total"], 1)
|
||||
self.assertEqual(summary["stat"]["teststeps"]["total"], 1)
|
||||
self.assertEqual(summary["stat"]["teststeps"]["successes"], 1)
|
||||
|
||||
req_resp_data = summary["details"][0]["records"][0]["meta_datas"]["data"]
|
||||
self.assertEqual(len(req_resp_data), 2)
|
||||
self.assertEqual(req_resp_data[0]["response"]["status_code"], 302)
|
||||
self.assertEqual(req_resp_data[1]["response"]["status_code"], 500)
|
||||
|
||||
def test_request_with_params(self):
|
||||
path = "tests/httpbin/api/302_redirect.yml"
|
||||
summary = self.runner.run(path)
|
||||
@@ -437,13 +450,17 @@ class TestHttpRunner(ApiServerUnittest):
|
||||
def test_run_api_folder(self):
|
||||
api_folder = "tests/httpbin/api/"
|
||||
summary = self.runner.run(api_folder)
|
||||
print(summary["stat"]["testcases"]["total"])
|
||||
print(len(summary["details"]))
|
||||
self.assertTrue(summary["success"])
|
||||
self.assertEqual(summary["stat"]["testcases"]["total"], 2)
|
||||
self.assertEqual(summary["stat"]["teststeps"]["total"], 2)
|
||||
self.assertEqual(summary["stat"]["teststeps"]["successes"], 2)
|
||||
self.assertEqual(len(summary["details"]), 2)
|
||||
self.assertEqual(summary["stat"]["testcases"]["total"], 3)
|
||||
self.assertEqual(summary["stat"]["teststeps"]["total"], 3)
|
||||
self.assertEqual(summary["stat"]["teststeps"]["successes"], 3)
|
||||
self.assertEqual(len(summary["details"]), 3)
|
||||
self.assertEqual(summary["details"][0]["stat"]["total"], 1)
|
||||
self.assertEqual(summary["details"][1]["stat"]["total"], 1)
|
||||
self.assertEqual(summary["details"][2]["stat"]["total"], 1)
|
||||
|
||||
|
||||
def test_run_testcase_hardcode(self):
|
||||
for testcase_file_path in self.testcase_file_path_list:
|
||||
|
||||
Reference in New Issue
Block a user