mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-12 16:01:27 +08:00
test: add example tests on httpbin
This commit is contained in:
36
examples/httpbin/hooks.yml
Normal file
36
examples/httpbin/hooks.yml
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
config:
|
||||||
|
name: basic test with httpbin
|
||||||
|
base_url: ${get_httpbin_server()}
|
||||||
|
setup_hooks:
|
||||||
|
- ${hook_print(setup)}
|
||||||
|
teardown_hooks:
|
||||||
|
- ${hook_print(teardown)}
|
||||||
|
|
||||||
|
teststeps:
|
||||||
|
-
|
||||||
|
name: headers
|
||||||
|
variables:
|
||||||
|
a: 123
|
||||||
|
request:
|
||||||
|
url: /headers
|
||||||
|
method: GET
|
||||||
|
setup_hooks:
|
||||||
|
- ${setup_hook_add_kwargs($request)}
|
||||||
|
- ${setup_hook_remove_kwargs($request)}
|
||||||
|
teardown_hooks:
|
||||||
|
- ${teardown_hook_sleep_N_secs($response, 1)}
|
||||||
|
validate:
|
||||||
|
- eq: ["status_code", 200]
|
||||||
|
- contained_by: [body.headers.Host, "${get_httpbin_server()}"]
|
||||||
|
|
||||||
|
-
|
||||||
|
name: alter response
|
||||||
|
request:
|
||||||
|
url: /headers
|
||||||
|
method: GET
|
||||||
|
teardown_hooks:
|
||||||
|
- ${alter_response($response)}
|
||||||
|
validate:
|
||||||
|
- eq: ["status_code", 200]
|
||||||
|
# - eq: ["headers.content-type", "html/text"]
|
||||||
|
- eq: [body.headers.Host, "httpbin.org"]
|
||||||
48
examples/httpbin/hooks_test.py
Normal file
48
examples/httpbin/hooks_test.py
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
# NOTICE: Generated By HttpRunner. DO'NOT EDIT!
|
||||||
|
from httprunner import HttpRunner, TConfig, TStep
|
||||||
|
|
||||||
|
|
||||||
|
class TestCaseHooks(HttpRunner):
|
||||||
|
config = TConfig(
|
||||||
|
**{
|
||||||
|
"name": "basic test with httpbin",
|
||||||
|
"base_url": "${get_httpbin_server()}",
|
||||||
|
"setup_hooks": ["${hook_print(setup)}"],
|
||||||
|
"teardown_hooks": ["${hook_print(teardown)}"],
|
||||||
|
"path": "examples/httpbin/hooks_test.py",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
teststeps = [
|
||||||
|
TStep(
|
||||||
|
**{
|
||||||
|
"name": "headers",
|
||||||
|
"variables": {"a": 123},
|
||||||
|
"request": {"url": "/headers", "method": "GET"},
|
||||||
|
"setup_hooks": [
|
||||||
|
"${setup_hook_add_kwargs($request)}",
|
||||||
|
"${setup_hook_remove_kwargs($request)}",
|
||||||
|
],
|
||||||
|
"teardown_hooks": ["${teardown_hook_sleep_N_secs($response, 1)}"],
|
||||||
|
"validate": [
|
||||||
|
{"eq": ["status_code", 200]},
|
||||||
|
{"contained_by": ["body.headers.Host", "${get_httpbin_server()}"]},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
),
|
||||||
|
TStep(
|
||||||
|
**{
|
||||||
|
"name": "alter response",
|
||||||
|
"request": {"url": "/headers", "method": "GET"},
|
||||||
|
"teardown_hooks": ["${alter_response($response)}"],
|
||||||
|
"validate": [
|
||||||
|
{"eq": ["status_code", 200]},
|
||||||
|
{"eq": ["body.headers.Host", "httpbin.org"]},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
TestCaseHooks().test_start()
|
||||||
37
examples/httpbin/load_image.yml
Normal file
37
examples/httpbin/load_image.yml
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
config:
|
||||||
|
name: load images
|
||||||
|
base_url: ${get_httpbin_server()}
|
||||||
|
|
||||||
|
teststeps:
|
||||||
|
-
|
||||||
|
name: get png image
|
||||||
|
request:
|
||||||
|
url: /image/png
|
||||||
|
method: GET
|
||||||
|
validate:
|
||||||
|
- eq: ["status_code", 200]
|
||||||
|
|
||||||
|
-
|
||||||
|
name: get jpeg image
|
||||||
|
request:
|
||||||
|
url: /image/jpeg
|
||||||
|
method: GET
|
||||||
|
validate:
|
||||||
|
- eq: ["status_code", 200]
|
||||||
|
|
||||||
|
-
|
||||||
|
name: get webp image
|
||||||
|
request:
|
||||||
|
url: /image/webp
|
||||||
|
method: GET
|
||||||
|
validate:
|
||||||
|
- eq: ["status_code", 200]
|
||||||
|
|
||||||
|
-
|
||||||
|
name: get svg image
|
||||||
|
request:
|
||||||
|
url: /image/svg
|
||||||
|
method: GET
|
||||||
|
validate:
|
||||||
|
- eq: ["status_code", 200]
|
||||||
|
|
||||||
47
examples/httpbin/load_image_test.py
Normal file
47
examples/httpbin/load_image_test.py
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
# NOTICE: Generated By HttpRunner. DO'NOT EDIT!
|
||||||
|
from httprunner import HttpRunner, TConfig, TStep
|
||||||
|
|
||||||
|
|
||||||
|
class TestCaseLoadImage(HttpRunner):
|
||||||
|
config = TConfig(
|
||||||
|
**{
|
||||||
|
"name": "load images",
|
||||||
|
"base_url": "${get_httpbin_server()}",
|
||||||
|
"path": "examples/httpbin/load_image_test.py",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
teststeps = [
|
||||||
|
TStep(
|
||||||
|
**{
|
||||||
|
"name": "get png image",
|
||||||
|
"request": {"url": "/image/png", "method": "GET"},
|
||||||
|
"validate": [{"eq": ["status_code", 200]}],
|
||||||
|
}
|
||||||
|
),
|
||||||
|
TStep(
|
||||||
|
**{
|
||||||
|
"name": "get jpeg image",
|
||||||
|
"request": {"url": "/image/jpeg", "method": "GET"},
|
||||||
|
"validate": [{"eq": ["status_code", 200]}],
|
||||||
|
}
|
||||||
|
),
|
||||||
|
TStep(
|
||||||
|
**{
|
||||||
|
"name": "get webp image",
|
||||||
|
"request": {"url": "/image/webp", "method": "GET"},
|
||||||
|
"validate": [{"eq": ["status_code", 200]}],
|
||||||
|
}
|
||||||
|
),
|
||||||
|
TStep(
|
||||||
|
**{
|
||||||
|
"name": "get svg image",
|
||||||
|
"request": {"url": "/image/svg", "method": "GET"},
|
||||||
|
"validate": [{"eq": ["status_code", 200]}],
|
||||||
|
}
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
TestCaseLoadImage().test_start()
|
||||||
@@ -123,9 +123,9 @@ def multipart_encoder(**kwargs):
|
|||||||
is_exists_file = os.path.isfile(value)
|
is_exists_file = os.path.isfile(value)
|
||||||
else:
|
else:
|
||||||
# value is not absolute file path, check if it is relative file path
|
# value is not absolute file path, check if it is relative file path
|
||||||
from httprunner.loader import get_pwd
|
from httprunner.loader import project_working_directory
|
||||||
|
|
||||||
_file_path = os.path.join(get_pwd(), value)
|
_file_path = os.path.join(project_working_directory, value)
|
||||||
is_exists_file = os.path.isfile(_file_path)
|
is_exists_file = os.path.isfile(_file_path)
|
||||||
|
|
||||||
if is_exists_file:
|
if is_exists_file:
|
||||||
|
|||||||
Reference in New Issue
Block a user