feat: support alter response in teardown hooks

This commit is contained in:
debugtalk
2020-06-07 19:04:06 +08:00
parent 0b53f832f1
commit 45d1f3ed65
18 changed files with 54 additions and 32 deletions

View File

@@ -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

View File

@@ -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}

View File

@@ -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"]

View File

@@ -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")
),
]

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -1,4 +1,4 @@
# NOTE: Generated By HttpRunner v3.0.9
# NOTE: Generated By HttpRunner v3.0.10
# FROM: examples/postman_echo/request_methods/request_with_functions.yml
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase

View File

@@ -1,4 +1,4 @@
# NOTE: Generated By HttpRunner v3.0.9
# NOTE: Generated By HttpRunner v3.0.10
# FROM: examples/postman_echo/request_methods/request_with_testcase_reference.yml
import os

View File

@@ -1,4 +1,4 @@
# NOTE: Generated By HttpRunner v3.0.9
# NOTE: Generated By HttpRunner v3.0.10
# FROM: examples/postman_echo/request_methods/hardcode.yml
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase

View File

@@ -1,4 +1,4 @@
# NOTE: Generated By HttpRunner v3.0.9
# NOTE: Generated By HttpRunner v3.0.10
# FROM: examples/postman_echo/request_methods/request_with_functions.yml
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase

View File

@@ -1,4 +1,4 @@
# NOTE: Generated By HttpRunner v3.0.9
# NOTE: Generated By HttpRunner v3.0.10
# FROM: examples/postman_echo/request_methods/request_with_testcase_reference.yml
import os

View File

@@ -1,4 +1,4 @@
# NOTE: Generated By HttpRunner v3.0.9
# NOTE: Generated By HttpRunner v3.0.10
# FROM: examples/postman_echo/request_methods/request_with_variables.yml
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase

View File

@@ -1,4 +1,4 @@
# NOTE: Generated By HttpRunner v3.0.9
# NOTE: Generated By HttpRunner v3.0.10
# FROM: examples/postman_echo/request_methods/validate_with_functions.yml
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase

View File

@@ -1,4 +1,4 @@
# NOTE: Generated By HttpRunner v3.0.9
# NOTE: Generated By HttpRunner v3.0.10
# FROM: examples/postman_echo/request_methods/validate_with_variables.yml
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase