feat: make pytest files in chain style

This commit is contained in:
debugtalk
2020-06-02 14:37:37 +08:00
parent e1e7ba7bea
commit 6fa680502e
21 changed files with 937 additions and 526 deletions

View File

@@ -1,82 +1,63 @@
# NOTICE: Generated By HttpRunner. DO NOT EDIT!
# FROM: examples/postman_echo/request_methods/validate_with_variables.yml
from httprunner import HttpRunner, TConfig, TStep
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
class TestCaseValidateWithVariables(HttpRunner):
config = TConfig(
**{
"name": "request methods testcase: validate with variables",
"variables": {"foo1": "session_bar1"},
"base_url": "https://postman-echo.com",
"verify": False,
"path": "examples/postman_echo/request_methods/validate_with_variables_test.py",
}
config = (
Config("request methods testcase: validate with variables")
.variables(**{"foo1": "session_bar1"})
.base_url("https://postman-echo.com")
.verify(False)
)
teststeps = [
TStep(
**{
"name": "get with params",
"variables": {"foo1": "bar1", "foo2": "session_bar2"},
"request": {
"method": "GET",
"url": "/get",
"params": {"foo1": "$foo1", "foo2": "$foo2"},
"headers": {"User-Agent": "HttpRunner/3.0"},
},
"extract": {"session_foo2": "body.args.foo2"},
"validate": [
{"eq": ["status_code", 200]},
{"eq": ["body.args.foo1", "$foo1"]},
{"eq": ["body.args.foo2", "$foo2"]},
],
}
Step(
RunRequest("get with params")
.with_variables(**{"foo1": "bar1", "foo2": "session_bar2"})
.get("/get")
.with_params(**{"foo1": "$foo1", "foo2": "$foo2"})
.with_headers(**{"User-Agent": "HttpRunner/3.0"})
.extract()
.with_jmespath("body.args.foo2", "session_foo2")
.validate()
.assert_equal("status_code", 200)
.assert_equal("body.args.foo1", "$foo1")
.assert_equal("body.args.foo2", "$foo2")
),
TStep(
**{
"name": "post raw text",
"variables": {"foo1": "hello world", "foo3": "$session_foo2"},
"request": {
"method": "POST",
"url": "/post",
"headers": {
"User-Agent": "HttpRunner/3.0",
"Content-Type": "text/plain",
},
"data": "This is expected to be sent back as part of response body: $foo1-$foo3.",
},
"validate": [
{"eq": ["status_code", 200]},
{
"eq": [
"body.data",
"This is expected to be sent back as part of response body: session_bar1-$foo3.",
]
},
],
}
Step(
RunRequest("post raw text")
.with_variables(**{"foo1": "hello world", "foo3": "$session_foo2"})
.post("/post")
.with_headers(
**{"User-Agent": "HttpRunner/3.0", "Content-Type": "text/plain"}
)
.with_data(
"This is expected to be sent back as part of response body: $foo1-$foo3."
)
.validate()
.assert_equal("status_code", 200)
.assert_equal(
"body.data",
"This is expected to be sent back as part of response body: session_bar1-$foo3.",
)
),
TStep(
**{
"name": "post form data",
"variables": {"foo1": "bar1", "foo2": "bar2"},
"request": {
"method": "POST",
"url": "/post",
"headers": {
"User-Agent": "HttpRunner/3.0",
"Content-Type": "application/x-www-form-urlencoded",
},
"data": "foo1=$foo1&foo2=$foo2",
},
"validate": [
{"eq": ["status_code", 200]},
{"eq": ["body.form.foo1", "$foo1"]},
{"eq": ["body.form.foo2", "$foo2"]},
],
}
Step(
RunRequest("post form data")
.with_variables(**{"foo1": "bar1", "foo2": "bar2"})
.post("/post")
.with_headers(
**{
"User-Agent": "HttpRunner/3.0",
"Content-Type": "application/x-www-form-urlencoded",
}
)
.with_data("foo1=$foo1&foo2=$foo2")
.validate()
.assert_equal("status_code", 200)
.assert_equal("body.form.foo1", "$foo1")
.assert_equal("body.form.foo2", "$foo2")
),
]