diff --git a/tests/debugtalk.py b/tests/debugtalk.py index 7006ddf8..101d6308 100644 --- a/tests/debugtalk.py +++ b/tests/debugtalk.py @@ -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 diff --git a/tests/httpbin/api/302_redirect_teardown_hook.yml b/tests/httpbin/api/302_redirect_teardown_hook.yml new file mode 100644 index 00000000..329d6d48 --- /dev/null +++ b/tests/httpbin/api/302_redirect_teardown_hook.yml @@ -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"] \ No newline at end of file diff --git a/tests/test_api.py b/tests/test_api.py index 97c59422..d4f2e125 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -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: