mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
refactor: post data with body
This commit is contained in:
@@ -69,7 +69,7 @@
|
||||
"request": {
|
||||
"method": "POST",
|
||||
"url": "/post",
|
||||
"json": {
|
||||
"body": {
|
||||
"foo1": "$varFoo1",
|
||||
"foo2": "${max($a, $b)}"
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ teststeps:
|
||||
request:
|
||||
method: POST
|
||||
url: /post
|
||||
json:
|
||||
body:
|
||||
foo1: $varFoo1
|
||||
foo2: ${max($a, $b)}
|
||||
validate:
|
||||
|
||||
@@ -39,7 +39,7 @@ func TestCaseDemo(t *testing.T) {
|
||||
AssertEqual("body.args.foo2", "34.5", "check args foo2"), // notice: request params value will be converted to string
|
||||
httpboomer.Step("post json data").
|
||||
POST("/post").
|
||||
WithJSON(map[string]interface{}{
|
||||
WithBody(map[string]interface{}{
|
||||
"foo1": "$varFoo1", // reference former extracted variable
|
||||
"foo2": "${max($a, $b)}", // 12.3; step level variables are independent, variable b is 3.45 here
|
||||
}).
|
||||
|
||||
@@ -74,7 +74,7 @@ func TestCaseExtractStepAssociation(t *testing.T) {
|
||||
httpboomer.Step("post json data").
|
||||
POST("/post").
|
||||
WithHeaders(map[string]string{"User-Agent": "HttpBoomer"}).
|
||||
WithJSON(map[string]interface{}{"foo1": "bar1", "foo2": "bar2"}).
|
||||
WithBody(map[string]interface{}{"foo1": "bar1", "foo2": "bar2"}).
|
||||
Validate().
|
||||
AssertEqual("status_code", "$statusCode", "check status code"). // assert with extracted variable from previous step
|
||||
AssertEqual("$varFoo1", "bar1", "check json foo1"). // assert with extracted variable from previous step
|
||||
|
||||
@@ -32,7 +32,7 @@ func TestCaseCallFunction(t *testing.T) {
|
||||
httpboomer.Step("post json data with functions").
|
||||
POST("/post").
|
||||
WithHeaders(map[string]string{"User-Agent": "HttpBoomer"}).
|
||||
WithJSON(map[string]interface{}{"foo1": "${gen_random_string($n)}", "foo2": "${max($a, $b)}"}).
|
||||
WithBody(map[string]interface{}{"foo1": "${gen_random_string($n)}", "foo2": "${max($a, $b)}"}).
|
||||
Validate().
|
||||
AssertEqual("status_code", 200, "check status code").
|
||||
AssertLengthEqual("body.json.foo1", 5, "check args foo1").
|
||||
|
||||
@@ -27,7 +27,7 @@ func TestCaseBasicRequest(t *testing.T) {
|
||||
httpboomer.Step("post raw text").
|
||||
POST("/post").
|
||||
WithHeaders(map[string]string{"User-Agent": "HttpBoomer", "Content-Type": "text/plain"}).
|
||||
WithData("This is expected to be sent back as part of response body.").
|
||||
WithBody("This is expected to be sent back as part of response body.").
|
||||
Validate().
|
||||
AssertEqual("status_code", 200, "check status code").
|
||||
AssertEqual("body.data", "This is expected to be sent back as part of response body.", "check data"),
|
||||
@@ -42,7 +42,7 @@ func TestCaseBasicRequest(t *testing.T) {
|
||||
httpboomer.Step("post json data").
|
||||
POST("/post").
|
||||
WithHeaders(map[string]string{"User-Agent": "HttpBoomer"}).
|
||||
WithJSON(map[string]interface{}{"foo1": "bar1", "foo2": "bar2"}).
|
||||
WithBody(map[string]interface{}{"foo1": "bar1", "foo2": "bar2"}).
|
||||
Validate().
|
||||
AssertEqual("status_code", 200, "check status code").
|
||||
AssertEqual("body.json.foo1", "bar1", "check json foo1").
|
||||
@@ -50,7 +50,7 @@ func TestCaseBasicRequest(t *testing.T) {
|
||||
httpboomer.Step("put request").
|
||||
PUT("/put").
|
||||
WithHeaders(map[string]string{"User-Agent": "HttpBoomer", "Content-Type": "text/plain"}).
|
||||
WithData("This is expected to be sent back as part of response body.").
|
||||
WithBody("This is expected to be sent back as part of response body.").
|
||||
Validate().
|
||||
AssertEqual("status_code", 200, "check status code").
|
||||
AssertEqual("body.data", "This is expected to be sent back as part of response body.", "check data"),
|
||||
|
||||
@@ -143,7 +143,7 @@ func TestCaseParseVariables(t *testing.T) {
|
||||
httpboomer.Step("post json data with functions").
|
||||
POST("/post").
|
||||
WithHeaders(map[string]string{"User-Agent": "HttpBoomer"}).
|
||||
WithJSON(map[string]interface{}{"foo1": "${gen_random_string($n)}", "foo2": "${max($a, $b)}"}).
|
||||
WithBody(map[string]interface{}{"foo1": "${gen_random_string($n)}", "foo2": "${max($a, $b)}"}).
|
||||
Validate().
|
||||
AssertEqual("status_code", 200, "check status code").
|
||||
AssertLengthEqual("body.json.foo1", 5, "check args foo1").
|
||||
|
||||
Reference in New Issue
Block a user