add unit test and closes #971

This commit is contained in:
jun
2020-07-28 12:49:26 +08:00
parent ac9664e842
commit fa30ce3bc7
5 changed files with 70 additions and 5 deletions

View File

@@ -55,3 +55,24 @@ teststeps:
- eq: ["body.form.foo1", "testcase_config_bar1"]
- eq: ["body.form.foo2", "bar23"]
- eq: ["body.form.foo3", "bar21"]
-
name: post form data using json
variables:
foo2: bar23
jsondata:
foo1: $foo1
foo2: $foo2
foo3: $foo3
request:
method: POST
url: /post
headers:
User-Agent: HttpRunner/3.0
Content-Type: "application/json"
json: $jsondata
validate:
- eq: ["status_code", 200]
- eq: ["body.data.foo1", "testcase_config_bar1"]
- eq: ["body.data.foo2", "bar23"]
- eq: ["body.data.foo3", "bar21"]

View File

@@ -1,5 +1,5 @@
# NOTE: Generated By HttpRunner v3.1.3
# FROM: request_methods/request_with_variables.yml
# FROM: request_methods\request_with_variables.yml
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
@@ -62,6 +62,25 @@ class TestCaseRequestWithVariables(HttpRunner):
.assert_equal("body.form.foo2", "bar23")
.assert_equal("body.form.foo3", "bar21")
),
Step(
RunRequest("post form data using json")
.with_variables(
**{
"foo2": "bar23",
"jsondata": {"foo1": "$foo1", "foo2": "$foo2", "foo3": "$foo3"},
}
)
.post("/post")
.with_headers(
**{"User-Agent": "HttpRunner/3.0", "Content-Type": "application/json"}
)
.with_json("$jsondata")
.validate()
.assert_equal("status_code", 200)
.assert_equal("body.data.foo1", "testcase_config_bar1")
.assert_equal("body.data.foo2", "bar23")
.assert_equal("body.data.foo3", "bar21")
),
]