mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-16 13:27:35 +08:00
docs: update changelog and example tests
This commit is contained in:
@@ -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)
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user