mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-11 18:11:21 +08:00
docs: update changelog and example tests
This commit is contained in:
1
examples/httpbin/__init__.py
Normal file
1
examples/httpbin/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
# NOTICE: Generated By HttpRunner. DO NOT EDIT!
|
||||
@@ -1,105 +1,76 @@
|
||||
# NOTICE: Generated By HttpRunner. DO NOT EDIT!
|
||||
# FROM: examples/httpbin/basic.yml
|
||||
|
||||
from httprunner import HttpRunner, TConfig, TStep
|
||||
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
|
||||
|
||||
|
||||
class TestCaseBasic(HttpRunner):
|
||||
config = TConfig(
|
||||
**{
|
||||
"name": "basic test with httpbin",
|
||||
"base_url": "https://httpbin.org/",
|
||||
"path": "examples/httpbin/basic_test.py",
|
||||
"variables": {},
|
||||
}
|
||||
)
|
||||
config = Config("basic test with httpbin").base_url("https://httpbin.org/")
|
||||
|
||||
teststeps = [
|
||||
TStep(
|
||||
**{
|
||||
"name": "headers",
|
||||
"request": {"url": "/headers", "method": "GET"},
|
||||
"validate": [
|
||||
{"eq": ["status_code", 200]},
|
||||
{"eq": ["body.headers.Host", "httpbin.org"]},
|
||||
],
|
||||
}
|
||||
Step(
|
||||
RunRequest("headers")
|
||||
.get("/headers")
|
||||
.validate()
|
||||
.assert_equal("status_code", 200)
|
||||
.assert_equal("body.headers.Host", "httpbin.org")
|
||||
),
|
||||
TStep(
|
||||
**{
|
||||
"name": "user-agent",
|
||||
"request": {"url": "/user-agent", "method": "GET"},
|
||||
"validate": [
|
||||
{"eq": ["status_code", 200]},
|
||||
{"startswith": ['body."user-agent"', "python-requests"]},
|
||||
],
|
||||
}
|
||||
Step(
|
||||
RunRequest("user-agent")
|
||||
.get("/user-agent")
|
||||
.validate()
|
||||
.assert_equal("status_code", 200)
|
||||
.assert_startswith('body."user-agent"', "python-requests")
|
||||
),
|
||||
TStep(
|
||||
**{
|
||||
"name": "get without params",
|
||||
"request": {"url": "/get", "method": "GET"},
|
||||
"validate": [{"eq": ["status_code", 200]}, {"eq": ["body.args", {}]}],
|
||||
}
|
||||
Step(
|
||||
RunRequest("get without params")
|
||||
.get("/get")
|
||||
.validate()
|
||||
.assert_equal("status_code", 200)
|
||||
.assert_equal("body.args", {})
|
||||
),
|
||||
TStep(
|
||||
**{
|
||||
"name": "get with params in url",
|
||||
"request": {"url": "/get?a=1&b=2", "method": "GET"},
|
||||
"validate": [
|
||||
{"eq": ["status_code", 200]},
|
||||
{"eq": ["body.args", {"a": "1", "b": "2"}]},
|
||||
],
|
||||
}
|
||||
Step(
|
||||
RunRequest("get with params in url")
|
||||
.get("/get?a=1&b=2")
|
||||
.validate()
|
||||
.assert_equal("status_code", 200)
|
||||
.assert_equal("body.args", {"a": "1", "b": "2"})
|
||||
),
|
||||
TStep(
|
||||
**{
|
||||
"name": "get with params in params field",
|
||||
"request": {"url": "/get", "params": {"a": 1, "b": 2}, "method": "GET"},
|
||||
"validate": [
|
||||
{"eq": ["status_code", 200]},
|
||||
{"eq": ["body.args", {"a": "1", "b": "2"}]},
|
||||
],
|
||||
}
|
||||
Step(
|
||||
RunRequest("get with params in params field")
|
||||
.get("/get")
|
||||
.with_params(**{"a": 1, "b": 2})
|
||||
.validate()
|
||||
.assert_equal("status_code", 200)
|
||||
.assert_equal("body.args", {"a": "1", "b": "2"})
|
||||
),
|
||||
TStep(
|
||||
**{
|
||||
"name": "set cookie",
|
||||
"request": {"url": "/cookies/set?name=value", "method": "GET"},
|
||||
"validate": [
|
||||
{"eq": ["status_code", 200]},
|
||||
{"eq": ["body.cookies.name", "value"]},
|
||||
],
|
||||
}
|
||||
Step(
|
||||
RunRequest("set cookie")
|
||||
.get("/cookies/set?name=value")
|
||||
.validate()
|
||||
.assert_equal("status_code", 200)
|
||||
.assert_equal("body.cookies.name", "value")
|
||||
),
|
||||
TStep(
|
||||
**{
|
||||
"name": "extract cookie",
|
||||
"request": {"url": "/cookies", "method": "GET"},
|
||||
"validate": [
|
||||
{"eq": ["status_code", 200]},
|
||||
{"eq": ["body.cookies.name", "value"]},
|
||||
],
|
||||
}
|
||||
Step(
|
||||
RunRequest("extract cookie")
|
||||
.get("/cookies")
|
||||
.validate()
|
||||
.assert_equal("status_code", 200)
|
||||
.assert_equal("body.cookies.name", "value")
|
||||
),
|
||||
TStep(
|
||||
**{
|
||||
"name": "post data",
|
||||
"request": {
|
||||
"url": "/post",
|
||||
"method": "POST",
|
||||
"headers": {"Content-Type": "application/json"},
|
||||
"data": "abc",
|
||||
},
|
||||
"validate": [{"eq": ["status_code", 200]}],
|
||||
}
|
||||
Step(
|
||||
RunRequest("post data")
|
||||
.post("/post")
|
||||
.with_headers(**{"Content-Type": "application/json"})
|
||||
.with_data("abc")
|
||||
.validate()
|
||||
.assert_equal("status_code", 200)
|
||||
),
|
||||
TStep(
|
||||
**{
|
||||
"name": "validate body length",
|
||||
"request": {"url": "/spec.json", "method": "GET"},
|
||||
"validate": [{"len_eq": ["body", 9]}],
|
||||
}
|
||||
Step(
|
||||
RunRequest("validate body length")
|
||||
.get("/spec.json")
|
||||
.validate()
|
||||
.assert_length_equal("body", 9)
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
@@ -1,48 +1,27 @@
|
||||
# NOTICE: Generated By HttpRunner. DO NOT EDIT!
|
||||
# FROM: examples/httpbin/hooks.yml
|
||||
|
||||
from httprunner import HttpRunner, TConfig, TStep
|
||||
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
|
||||
|
||||
|
||||
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",
|
||||
"variables": {},
|
||||
}
|
||||
)
|
||||
config = Config("basic test with httpbin").base_url("${get_httpbin_server()}")
|
||||
|
||||
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()}"]},
|
||||
],
|
||||
}
|
||||
Step(
|
||||
RunRequest("headers")
|
||||
.with_variables(**{"a": 123})
|
||||
.get("/headers")
|
||||
.validate()
|
||||
.assert_equal("status_code", 200)
|
||||
.assert_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"]},
|
||||
],
|
||||
}
|
||||
Step(
|
||||
RunRequest("alter response")
|
||||
.get("/headers")
|
||||
.validate()
|
||||
.assert_equal("status_code", 200)
|
||||
.assert_equal("body.headers.Host", "httpbin.org")
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
@@ -1,47 +1,36 @@
|
||||
# NOTICE: Generated By HttpRunner. DO NOT EDIT!
|
||||
# FROM: examples/httpbin/load_image.yml
|
||||
|
||||
from httprunner import HttpRunner, TConfig, TStep
|
||||
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
|
||||
|
||||
|
||||
class TestCaseLoadImage(HttpRunner):
|
||||
config = TConfig(
|
||||
**{
|
||||
"name": "load images",
|
||||
"base_url": "${get_httpbin_server()}",
|
||||
"path": "examples/httpbin/load_image_test.py",
|
||||
"variables": {},
|
||||
}
|
||||
)
|
||||
config = Config("load images").base_url("${get_httpbin_server()}")
|
||||
|
||||
teststeps = [
|
||||
TStep(
|
||||
**{
|
||||
"name": "get png image",
|
||||
"request": {"url": "/image/png", "method": "GET"},
|
||||
"validate": [{"eq": ["status_code", 200]}],
|
||||
}
|
||||
Step(
|
||||
RunRequest("get png image")
|
||||
.get("/image/png")
|
||||
.validate()
|
||||
.assert_equal("status_code", 200)
|
||||
),
|
||||
TStep(
|
||||
**{
|
||||
"name": "get jpeg image",
|
||||
"request": {"url": "/image/jpeg", "method": "GET"},
|
||||
"validate": [{"eq": ["status_code", 200]}],
|
||||
}
|
||||
Step(
|
||||
RunRequest("get jpeg image")
|
||||
.get("/image/jpeg")
|
||||
.validate()
|
||||
.assert_equal("status_code", 200)
|
||||
),
|
||||
TStep(
|
||||
**{
|
||||
"name": "get webp image",
|
||||
"request": {"url": "/image/webp", "method": "GET"},
|
||||
"validate": [{"eq": ["status_code", 200]}],
|
||||
}
|
||||
Step(
|
||||
RunRequest("get webp image")
|
||||
.get("/image/webp")
|
||||
.validate()
|
||||
.assert_equal("status_code", 200)
|
||||
),
|
||||
TStep(
|
||||
**{
|
||||
"name": "get svg image",
|
||||
"request": {"url": "/image/svg", "method": "GET"},
|
||||
"validate": [{"eq": ["status_code", 200]}],
|
||||
}
|
||||
Step(
|
||||
RunRequest("get svg image")
|
||||
.get("/image/svg")
|
||||
.validate()
|
||||
.assert_equal("status_code", 200)
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
@@ -13,8 +13,8 @@ teststeps:
|
||||
method: GET
|
||||
validate:
|
||||
- eq: ["status_code", 200]
|
||||
- eq: ["body.args.a", 1]
|
||||
- eq: ["body.args.b", 2]
|
||||
- eq: ["body.args.a", "1"]
|
||||
- eq: ["body.args.b", "2"]
|
||||
validate_script:
|
||||
- "assert status_code == 200"
|
||||
|
||||
|
||||
@@ -1,43 +1,28 @@
|
||||
# NOTICE: Generated By HttpRunner. DO NOT EDIT!
|
||||
# FROM: examples/httpbin/validate.yml
|
||||
|
||||
from httprunner import HttpRunner, TConfig, TStep
|
||||
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
|
||||
|
||||
|
||||
class TestCaseValidate(HttpRunner):
|
||||
config = TConfig(
|
||||
**{
|
||||
"name": "basic test with httpbin",
|
||||
"base_url": "http://httpbin.org/",
|
||||
"path": "examples/httpbin/validate_test.py",
|
||||
"variables": {},
|
||||
}
|
||||
)
|
||||
config = Config("basic test with httpbin").base_url("http://httpbin.org/")
|
||||
|
||||
teststeps = [
|
||||
TStep(
|
||||
**{
|
||||
"name": "validate response with json path",
|
||||
"request": {"url": "/get", "params": {"a": 1, "b": 2}, "method": "GET"},
|
||||
"validate": [
|
||||
{"eq": ["status_code", 200]},
|
||||
{"eq": ["body.args.a", 1]},
|
||||
{"eq": ["body.args.b", 2]},
|
||||
],
|
||||
"validate_script": ["assert status_code == 200"],
|
||||
}
|
||||
Step(
|
||||
RunRequest("validate response with json path")
|
||||
.get("/get")
|
||||
.with_params(**{"a": 1, "b": 2})
|
||||
.validate()
|
||||
.assert_equal("status_code", 200)
|
||||
.assert_equal("body.args.a", "1")
|
||||
.assert_equal("body.args.b", "2")
|
||||
),
|
||||
TStep(
|
||||
**{
|
||||
"name": "validate response with python script",
|
||||
"request": {"url": "/get", "params": {"a": 1, "b": 2}, "method": "GET"},
|
||||
"validate": [{"eq": ["status_code", 200]}],
|
||||
"validate_script": [
|
||||
"assert status_code == 201",
|
||||
"a = response_json.get('args').get('a')",
|
||||
"assert a == '1'",
|
||||
],
|
||||
}
|
||||
Step(
|
||||
RunRequest("validate response with python script")
|
||||
.get("/get")
|
||||
.with_params(**{"a": 1, "b": 2})
|
||||
.validate()
|
||||
.assert_equal("status_code", 200)
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user