mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-11 10:00:23 +08:00
feat: support alter response in teardown hooks
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# NOTE: Generated By HttpRunner v3.0.9
|
||||
# NOTE: Generated By HttpRunner v3.0.10
|
||||
# FROM: examples/httpbin/basic.yml
|
||||
|
||||
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
|
||||
|
||||
@@ -126,7 +126,7 @@ def setup_hook_httpntlmauth(request):
|
||||
def alter_response(response):
|
||||
response.status_code = 500
|
||||
response.headers["Content-Type"] = "html/text"
|
||||
response.json["headers"]["Host"] = "127.0.0.1:8888"
|
||||
response.body["headers"]["Host"] = "127.0.0.1:8888"
|
||||
response.new_attribute = "new_attribute_value"
|
||||
response.new_attribute_dict = {"key": 123}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ teststeps:
|
||||
teardown_hooks:
|
||||
- ${alter_response($response)}
|
||||
validate:
|
||||
- eq: ["status_code", 200]
|
||||
# TODO: implement hooks
|
||||
# - eq: [body.headers."Content-Type", "html/text"]
|
||||
- eq: [body.headers.Host, "httpbin.org"]
|
||||
- eq: ["status_code", 500]
|
||||
- eq: [headers."Content-Type", "html/text"]
|
||||
- eq: [body.headers."Content-Type", "application/json"]
|
||||
- eq: [body.headers.Host, "127.0.0.1:8888"]
|
||||
|
||||
@@ -24,8 +24,10 @@ class TestCaseHooks(HttpRunner):
|
||||
.get("/headers")
|
||||
.teardown_hook("${alter_response($response)}")
|
||||
.validate()
|
||||
.assert_equal("status_code", 200)
|
||||
.assert_equal("body.headers.Host", "httpbin.org")
|
||||
.assert_equal("status_code", 500)
|
||||
.assert_equal('headers."Content-Type"', "html/text")
|
||||
.assert_equal('body.headers."Content-Type"', "application/json")
|
||||
.assert_equal("body.headers.Host", "127.0.0.1:8888")
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# NOTE: Generated By HttpRunner v3.0.9
|
||||
# NOTE: Generated By HttpRunner v3.0.10
|
||||
# FROM: examples/httpbin/load_image.yml
|
||||
|
||||
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# NOTE: Generated By HttpRunner v3.0.9
|
||||
# NOTE: Generated By HttpRunner v3.0.10
|
||||
# FROM: examples/httpbin/upload.yml
|
||||
|
||||
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# NOTE: Generated By HttpRunner v3.0.9
|
||||
# NOTE: Generated By HttpRunner v3.0.10
|
||||
# FROM: examples/httpbin/validate.yml
|
||||
|
||||
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
|
||||
|
||||
Reference in New Issue
Block a user