mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-30 12:59:39 +08:00
feat: make pytest files in chain style
This commit is contained in:
@@ -1 +1 @@
|
||||
# NOTICE: Generated By HttpRunner. DO NOT EDIT!
|
||||
# NOTICE: Generated By HttpRunner. DO NOT EDIT!
|
||||
|
||||
@@ -1,87 +1,69 @@
|
||||
# NOTICE: Generated By HttpRunner. DO NOT EDIT!
|
||||
# FROM: examples/postman_echo/request_methods/request_with_functions.yml
|
||||
|
||||
from httprunner import HttpRunner, TConfig, TStep
|
||||
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
|
||||
|
||||
|
||||
class TestCaseRequestWithFunctions(HttpRunner):
|
||||
config = TConfig(
|
||||
**{
|
||||
"name": "request with functions",
|
||||
"variables": {"foo1": "session_bar1", "var1": "testsuite_val1"},
|
||||
"base_url": "https://postman-echo.com",
|
||||
"verify": False,
|
||||
"path": "examples/postman_echo/request_methods/demo_testsuite_yml/request_with_functions_test.py",
|
||||
}
|
||||
config = (
|
||||
Config("request with functions")
|
||||
.variables(**{"foo1": "session_bar1", "var1": "testsuite_val1"})
|
||||
.base_url("https://postman-echo.com")
|
||||
.verify(False)
|
||||
)
|
||||
|
||||
teststeps = [
|
||||
TStep(
|
||||
**{
|
||||
"name": "get with params",
|
||||
"variables": {
|
||||
"foo1": "bar1",
|
||||
"foo2": "session_bar2",
|
||||
"sum_v": "${sum_two(1, 2)}",
|
||||
},
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"url": "/get",
|
||||
"params": {"foo1": "$foo1", "foo2": "$foo2", "sum_v": "$sum_v"},
|
||||
"headers": {"User-Agent": "HttpRunner/${get_httprunner_version()}"},
|
||||
},
|
||||
"extract": {"session_foo2": "body.args.foo2"},
|
||||
"validate": [
|
||||
{"eq": ["status_code", 200]},
|
||||
{"eq": ["body.args.foo1", "session_bar1"]},
|
||||
{"eq": ["body.args.sum_v", "3"]},
|
||||
{"eq": ["body.args.foo2", "session_bar2"]},
|
||||
],
|
||||
}
|
||||
Step(
|
||||
RunRequest("get with params")
|
||||
.with_variables(
|
||||
**{"foo1": "bar1", "foo2": "session_bar2", "sum_v": "${sum_two(1, 2)}"}
|
||||
)
|
||||
.get("/get")
|
||||
.with_params(**{"foo1": "$foo1", "foo2": "$foo2", "sum_v": "$sum_v"})
|
||||
.with_headers(**{"User-Agent": "HttpRunner/${get_httprunner_version()}"})
|
||||
.extract()
|
||||
.with_jmespath("body.args.foo2", "session_foo2")
|
||||
.validate()
|
||||
.assert_equal("status_code", 200)
|
||||
.assert_equal("body.args.foo1", "session_bar1")
|
||||
.assert_equal("body.args.sum_v", "3")
|
||||
.assert_equal("body.args.foo2", "session_bar2")
|
||||
),
|
||||
TStep(
|
||||
**{
|
||||
"name": "post raw text",
|
||||
"variables": {"foo1": "hello world", "foo3": "$session_foo2"},
|
||||
"request": {
|
||||
"method": "POST",
|
||||
"url": "/post",
|
||||
"headers": {
|
||||
"User-Agent": "HttpRunner/${get_httprunner_version()}",
|
||||
"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-session_bar2.",
|
||||
]
|
||||
},
|
||||
],
|
||||
}
|
||||
Step(
|
||||
RunRequest("post raw text")
|
||||
.with_variables(**{"foo1": "hello world", "foo3": "$session_foo2"})
|
||||
.post("/post")
|
||||
.with_headers(
|
||||
**{
|
||||
"User-Agent": "HttpRunner/${get_httprunner_version()}",
|
||||
"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-session_bar2.",
|
||||
)
|
||||
),
|
||||
TStep(
|
||||
**{
|
||||
"name": "post form data",
|
||||
"variables": {"foo1": "bar1", "foo2": "bar2"},
|
||||
"request": {
|
||||
"method": "POST",
|
||||
"url": "/post",
|
||||
"headers": {
|
||||
"User-Agent": "HttpRunner/${get_httprunner_version()}",
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
},
|
||||
"data": "foo1=$foo1&foo2=$foo2",
|
||||
},
|
||||
"validate": [
|
||||
{"eq": ["status_code", 200]},
|
||||
{"eq": ["body.form.foo1", "session_bar1"]},
|
||||
{"eq": ["body.form.foo2", "bar2"]},
|
||||
],
|
||||
}
|
||||
Step(
|
||||
RunRequest("post form data")
|
||||
.with_variables(**{"foo1": "bar1", "foo2": "bar2"})
|
||||
.post("/post")
|
||||
.with_headers(
|
||||
**{
|
||||
"User-Agent": "HttpRunner/${get_httprunner_version()}",
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
}
|
||||
)
|
||||
.with_data("foo1=$foo1&foo2=$foo2")
|
||||
.validate()
|
||||
.assert_equal("status_code", 200)
|
||||
.assert_equal("body.form.foo1", "session_bar1")
|
||||
.assert_equal("body.form.foo2", "bar2")
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import sys
|
||||
|
||||
sys.path.insert(0, os.getcwd())
|
||||
|
||||
from httprunner import HttpRunner, TConfig, TStep
|
||||
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
|
||||
|
||||
from examples.postman_echo.request_methods.request_with_functions_test import (
|
||||
TestCaseRequestWithFunctions as RequestWithFunctions,
|
||||
@@ -14,23 +14,18 @@ from examples.postman_echo.request_methods.request_with_functions_test import (
|
||||
|
||||
|
||||
class TestCaseRequestWithTestcaseReference(HttpRunner):
|
||||
config = TConfig(
|
||||
**{
|
||||
"name": "request with referenced testcase",
|
||||
"variables": {"foo1": "session_bar1", "var2": "testsuite_val2"},
|
||||
"base_url": "https://postman-echo.com",
|
||||
"verify": False,
|
||||
"path": "examples/postman_echo/request_methods/demo_testsuite_yml/request_with_testcase_reference_test.py",
|
||||
}
|
||||
config = (
|
||||
Config("request with referenced testcase")
|
||||
.variables(**{"foo1": "session_bar1", "var2": "testsuite_val2"})
|
||||
.base_url("https://postman-echo.com")
|
||||
.verify(False)
|
||||
)
|
||||
|
||||
teststeps = [
|
||||
TStep(
|
||||
**{
|
||||
"name": "request with functions",
|
||||
"variables": {"foo1": "override_bar1"},
|
||||
"testcase": RequestWithFunctions,
|
||||
}
|
||||
Step(
|
||||
RunTestCase("request with functions")
|
||||
.with_variables(**{"foo1": "override_bar1"})
|
||||
.call(RequestWithFunctions)
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
@@ -1,77 +1,57 @@
|
||||
# NOTICE: Generated By HttpRunner. DO NOT EDIT!
|
||||
# FROM: examples/postman_echo/request_methods/hardcode.yml
|
||||
|
||||
from httprunner import HttpRunner, TConfig, TStep
|
||||
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
|
||||
|
||||
|
||||
class TestCaseHardcode(HttpRunner):
|
||||
config = TConfig(
|
||||
**{
|
||||
"name": "request methods testcase in hardcode",
|
||||
"base_url": "https://postman-echo.com",
|
||||
"verify": False,
|
||||
"path": "examples/postman_echo/request_methods/hardcode_test.py",
|
||||
"variables": {},
|
||||
}
|
||||
config = (
|
||||
Config("request methods testcase in hardcode")
|
||||
.base_url("https://postman-echo.com")
|
||||
.verify(False)
|
||||
)
|
||||
|
||||
teststeps = [
|
||||
TStep(
|
||||
**{
|
||||
"name": "get with params",
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"url": "/get",
|
||||
"params": {"foo1": "bar1", "foo2": "bar2"},
|
||||
"headers": {"User-Agent": "HttpRunner/3.0"},
|
||||
},
|
||||
"validate": [{"eq": ["status_code", 200]}],
|
||||
}
|
||||
Step(
|
||||
RunRequest("get with params")
|
||||
.get("/get")
|
||||
.with_params(**{"foo1": "bar1", "foo2": "bar2"})
|
||||
.with_headers(**{"User-Agent": "HttpRunner/3.0"})
|
||||
.validate()
|
||||
.assert_equal("status_code", 200)
|
||||
),
|
||||
TStep(
|
||||
**{
|
||||
"name": "post raw text",
|
||||
"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.",
|
||||
},
|
||||
"validate": [{"eq": ["status_code", 200]}],
|
||||
}
|
||||
Step(
|
||||
RunRequest("post raw text")
|
||||
.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.")
|
||||
.validate()
|
||||
.assert_equal("status_code", 200)
|
||||
),
|
||||
TStep(
|
||||
**{
|
||||
"name": "post form data",
|
||||
"request": {
|
||||
"method": "POST",
|
||||
"url": "/post",
|
||||
"headers": {
|
||||
"User-Agent": "HttpRunner/3.0",
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
},
|
||||
"data": "foo1=bar1&foo2=bar2",
|
||||
},
|
||||
"validate": [{"eq": ["status_code", 200]}],
|
||||
}
|
||||
Step(
|
||||
RunRequest("post form data")
|
||||
.post("/post")
|
||||
.with_headers(
|
||||
**{
|
||||
"User-Agent": "HttpRunner/3.0",
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
}
|
||||
)
|
||||
.with_data("foo1=bar1&foo2=bar2")
|
||||
.validate()
|
||||
.assert_equal("status_code", 200)
|
||||
),
|
||||
TStep(
|
||||
**{
|
||||
"name": "put request",
|
||||
"request": {
|
||||
"method": "PUT",
|
||||
"url": "/put",
|
||||
"headers": {
|
||||
"User-Agent": "HttpRunner/3.0",
|
||||
"Content-Type": "text/plain",
|
||||
},
|
||||
"data": "This is expected to be sent back as part of response body.",
|
||||
},
|
||||
"validate": [{"eq": ["status_code", 200]}],
|
||||
}
|
||||
Step(
|
||||
RunRequest("put request")
|
||||
.put("/put")
|
||||
.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.")
|
||||
.validate()
|
||||
.assert_equal("status_code", 200)
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
@@ -1,67 +1,88 @@
|
||||
# NOTICE: Generated By HttpRunner. DO NOT EDIT!
|
||||
# FROM: examples/postman_echo/request_methods/request_with_functions.yml
|
||||
|
||||
from httprunner import HttpRunner, Config, Step, Request
|
||||
from httprunner import HttpRunner, TConfig, TStep
|
||||
|
||||
|
||||
class TestCaseRequestWithFunctions(HttpRunner):
|
||||
config = (
|
||||
Config("request methods testcase with functions")
|
||||
.variables(foo1="session_bar1")
|
||||
.base_url("https://postman-echo.com")
|
||||
.verify(False)
|
||||
config = TConfig(
|
||||
**{
|
||||
"name": "request methods testcase with functions",
|
||||
"variables": {"foo1": "session_bar1"},
|
||||
"base_url": "https://postman-echo.com",
|
||||
"verify": False,
|
||||
"path": "examples/postman_echo/request_methods/request_with_functions_test.py",
|
||||
}
|
||||
)
|
||||
|
||||
teststeps = [
|
||||
Step("get with params")
|
||||
.with_variables(foo1="bar1", foo2="session_bar2", sum_v="${sum_two(1, 2)}")
|
||||
.set_extractor("session_foo2", "body.args.foo2")
|
||||
.run_request(
|
||||
Request()
|
||||
.get("/get")
|
||||
.with_params(foo1="$foo1", foo2="$foo2", sum_v="$sum_v")
|
||||
.with_headers(**{"User-Agent": "HttpRunner/${get_httprunner_version()}"})
|
||||
)
|
||||
.assert_equal("status_code", 200)
|
||||
.assert_equal("body.args.foo1", "session_bar1")
|
||||
.assert_equal("body.args.sum_v", "3")
|
||||
.assert_equal("body.args.foo2", "session_bar2"),
|
||||
Step("post raw text")
|
||||
.with_variables(foo1="hello world", foo3="$session_foo2")
|
||||
.run_request(
|
||||
Request()
|
||||
.post("/post")
|
||||
.with_headers(
|
||||
**{
|
||||
"User-Agent": "HttpRunner/${get_httprunner_version()}",
|
||||
"Content-Type": "text/plain",
|
||||
}
|
||||
)
|
||||
.with_data(
|
||||
"This is expected to be sent back as part of response body: $foo1-$foo3."
|
||||
)
|
||||
)
|
||||
.assert_equal("status_code", 200)
|
||||
.assert_equal(
|
||||
"body.data",
|
||||
"This is expected to be sent back as part of response body: session_bar1-session_bar2.",
|
||||
TStep(
|
||||
**{
|
||||
"name": "get with params",
|
||||
"variables": {
|
||||
"foo1": "bar1",
|
||||
"foo2": "session_bar2",
|
||||
"sum_v": "${sum_two(1, 2)}",
|
||||
},
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"url": "/get",
|
||||
"params": {"foo1": "$foo1", "foo2": "$foo2", "sum_v": "$sum_v"},
|
||||
"headers": {"User-Agent": "HttpRunner/${get_httprunner_version()}"},
|
||||
},
|
||||
"extract": {"session_foo2": "body.args.foo2"},
|
||||
"validate": [
|
||||
{"eq": ["status_code", 200]},
|
||||
{"eq": ["body.args.foo1", "session_bar1"]},
|
||||
{"eq": ["body.args.sum_v", "3"]},
|
||||
{"eq": ["body.args.foo2", "session_bar2"]},
|
||||
],
|
||||
}
|
||||
),
|
||||
TStep(
|
||||
**{
|
||||
"name": "post raw text",
|
||||
"variables": {"foo1": "hello world", "foo3": "$session_foo2"},
|
||||
"request": {
|
||||
"method": "POST",
|
||||
"url": "/post",
|
||||
"headers": {
|
||||
"User-Agent": "HttpRunner/${get_httprunner_version()}",
|
||||
"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-session_bar2.",
|
||||
]
|
||||
},
|
||||
],
|
||||
}
|
||||
),
|
||||
TStep(
|
||||
**{
|
||||
"name": "post form data",
|
||||
"variables": {"foo1": "bar1", "foo2": "bar2"},
|
||||
"request": {
|
||||
"method": "POST",
|
||||
"url": "/post",
|
||||
"headers": {
|
||||
"User-Agent": "HttpRunner/${get_httprunner_version()}",
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
},
|
||||
"data": "foo1=$foo1&foo2=$foo2",
|
||||
},
|
||||
"validate": [
|
||||
{"eq": ["status_code", 200]},
|
||||
{"eq": ["body.form.foo1", "session_bar1"]},
|
||||
{"eq": ["body.form.foo2", "bar2"]},
|
||||
],
|
||||
}
|
||||
),
|
||||
Step("post form data")
|
||||
.with_variables(**{"foo1": "bar1", "foo2": "bar2"})
|
||||
.run_request(
|
||||
Request()
|
||||
.post("/post")
|
||||
.with_headers(
|
||||
**{
|
||||
"User-Agent": "HttpRunner/${get_httprunner_version()}",
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
}
|
||||
)
|
||||
.with_data("foo1=$foo1&foo2=$foo2")
|
||||
)
|
||||
.assert_equal("status_code", 200)
|
||||
.assert_equal("body.form.foo1", "session_bar1")
|
||||
.assert_equal("body.form.foo2", "bar2"),
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import sys
|
||||
|
||||
sys.path.insert(0, os.getcwd())
|
||||
|
||||
from httprunner import HttpRunner, Config, Step
|
||||
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
|
||||
|
||||
from examples.postman_echo.request_methods.request_with_functions_test import (
|
||||
TestCaseRequestWithFunctions as RequestWithFunctions,
|
||||
@@ -16,15 +16,17 @@ from examples.postman_echo.request_methods.request_with_functions_test import (
|
||||
class TestCaseRequestWithTestcaseReference(HttpRunner):
|
||||
config = (
|
||||
Config("request methods testcase: reference testcase")
|
||||
.variables(foo1="session_bar1")
|
||||
.variables(**{"foo1": "session_bar1"})
|
||||
.base_url("https://postman-echo.com")
|
||||
.verify(False)
|
||||
)
|
||||
|
||||
teststeps = [
|
||||
Step("request with functions")
|
||||
.with_variables(foo1="override_bar1")
|
||||
.run_testcase(RequestWithFunctions),
|
||||
Step(
|
||||
RunTestCase("request with functions")
|
||||
.with_variables(**{"foo1": "override_bar1"})
|
||||
.call(RequestWithFunctions)
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -1,82 +1,63 @@
|
||||
# NOTICE: Generated By HttpRunner. DO NOT EDIT!
|
||||
# FROM: examples/postman_echo/request_methods/request_with_variables.yml
|
||||
|
||||
from httprunner import HttpRunner, TConfig, TStep
|
||||
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
|
||||
|
||||
|
||||
class TestCaseRequestWithVariables(HttpRunner):
|
||||
config = TConfig(
|
||||
**{
|
||||
"name": "request methods testcase with variables",
|
||||
"variables": {"foo1": "session_bar1"},
|
||||
"base_url": "https://postman-echo.com",
|
||||
"verify": False,
|
||||
"path": "examples/postman_echo/request_methods/request_with_variables_test.py",
|
||||
}
|
||||
config = (
|
||||
Config("request methods testcase 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", "session_bar1"]},
|
||||
{"eq": ["body.args.foo2", "session_bar2"]},
|
||||
],
|
||||
}
|
||||
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", "session_bar1")
|
||||
.assert_equal("body.args.foo2", "session_bar2")
|
||||
),
|
||||
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-session_bar2.",
|
||||
]
|
||||
},
|
||||
],
|
||||
}
|
||||
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-session_bar2.",
|
||||
)
|
||||
),
|
||||
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", "session_bar1"]},
|
||||
{"eq": ["body.form.foo2", "bar2"]},
|
||||
],
|
||||
}
|
||||
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", "session_bar1")
|
||||
.assert_equal("body.form.foo2", "bar2")
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
@@ -1,41 +1,31 @@
|
||||
# NOTICE: Generated By HttpRunner. DO NOT EDIT!
|
||||
# FROM: examples/postman_echo/request_methods/validate_with_functions.yml
|
||||
|
||||
from httprunner import HttpRunner, TConfig, TStep
|
||||
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
|
||||
|
||||
|
||||
class TestCaseValidateWithFunctions(HttpRunner):
|
||||
config = TConfig(
|
||||
**{
|
||||
"name": "request methods testcase: validate with functions",
|
||||
"variables": {"foo1": "session_bar1"},
|
||||
"base_url": "https://postman-echo.com",
|
||||
"verify": False,
|
||||
"path": "examples/postman_echo/request_methods/validate_with_functions_test.py",
|
||||
}
|
||||
config = (
|
||||
Config("request methods testcase: validate with functions")
|
||||
.variables(**{"foo1": "session_bar1"})
|
||||
.base_url("https://postman-echo.com")
|
||||
.verify(False)
|
||||
)
|
||||
|
||||
teststeps = [
|
||||
TStep(
|
||||
**{
|
||||
"name": "get with params",
|
||||
"variables": {
|
||||
"foo1": "bar1",
|
||||
"foo2": "session_bar2",
|
||||
"sum_v": "${sum_two(1, 2)}",
|
||||
},
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"url": "/get",
|
||||
"params": {"foo1": "$foo1", "foo2": "$foo2", "sum_v": "$sum_v"},
|
||||
"headers": {"User-Agent": "HttpRunner/${get_httprunner_version()}"},
|
||||
},
|
||||
"extract": {"session_foo2": "body.args.foo2"},
|
||||
"validate": [
|
||||
{"eq": ["status_code", 200]},
|
||||
{"eq": ["body.args.sum_v", "3"]},
|
||||
],
|
||||
}
|
||||
Step(
|
||||
RunRequest("get with params")
|
||||
.with_variables(
|
||||
**{"foo1": "bar1", "foo2": "session_bar2", "sum_v": "${sum_two(1, 2)}"}
|
||||
)
|
||||
.get("/get")
|
||||
.with_params(**{"foo1": "$foo1", "foo2": "$foo2", "sum_v": "$sum_v"})
|
||||
.with_headers(**{"User-Agent": "HttpRunner/${get_httprunner_version()}"})
|
||||
.extract()
|
||||
.with_jmespath("body.args.foo2", "session_foo2")
|
||||
.validate()
|
||||
.assert_equal("status_code", 200)
|
||||
.assert_equal("body.args.sum_v", "3")
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
@@ -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")
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user