mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-12 16:01:27 +08:00
fix startswith endswith and unittest
Change-Id: I3e1c6fd82812d13b4e23ecd6b23c4d57170852e1
This commit is contained in:
@@ -39,8 +39,8 @@ Currently, HttpRunner+ has the following built-in assertion functions.
|
|||||||
| `contained_by` | contained by | A in B | 'a' contained_by 'abc', 1 contained_by [1,2] |
|
| `contained_by` | contained by | A in B | 'a' contained_by 'abc', 1 contained_by [1,2] |
|
||||||
| `type_match` | A and B are in the same type | type(A) == type(B) | 123 type_match 1 |
|
| `type_match` | A and B are in the same type | type(A) == type(B) | 123 type_match 1 |
|
||||||
| `regex_match` | regex matches | re.match(B, A) | 'abcdef' regex_match 'a\w+d' |
|
| `regex_match` | regex matches | re.match(B, A) | 'abcdef' regex_match 'a\w+d' |
|
||||||
| `starts_with` | starts with | A.starts_with(B) is True | 'abc' starts_with 'ab' |
|
| `startswith` | starts with | A.startswith(B) is True | 'abc' startswith 'ab' |
|
||||||
| `ends_with` | ends with | A.ends_with(B) is True | 'abc' ends_with 'bc' |
|
| `endswith` | ends with | A.endswith(B) is True | 'abc' endswith 'bc' |
|
||||||
|
|
||||||
## Builtin functions
|
## Builtin functions
|
||||||
|
|
||||||
|
|||||||
@@ -33,4 +33,4 @@ Copyright 2021 debugtalk
|
|||||||
* [hrp run](hrp_run.md) - run API test
|
* [hrp run](hrp_run.md) - run API test
|
||||||
* [hrp startproject](hrp_startproject.md) - create a scaffold project
|
* [hrp startproject](hrp_startproject.md) - create a scaffold project
|
||||||
|
|
||||||
###### Auto generated by spf13/cobra on 14-Feb-2022
|
###### Auto generated by spf13/cobra on 15-Feb-2022
|
||||||
|
|||||||
@@ -39,4 +39,4 @@ hrp boom [flags]
|
|||||||
|
|
||||||
* [hrp](hrp.md) - One-stop solution for HTTP(S) testing.
|
* [hrp](hrp.md) - One-stop solution for HTTP(S) testing.
|
||||||
|
|
||||||
###### Auto generated by spf13/cobra on 14-Feb-2022
|
###### Auto generated by spf13/cobra on 15-Feb-2022
|
||||||
|
|||||||
@@ -23,4 +23,4 @@ hrp har2case $har_path... [flags]
|
|||||||
|
|
||||||
* [hrp](hrp.md) - One-stop solution for HTTP(S) testing.
|
* [hrp](hrp.md) - One-stop solution for HTTP(S) testing.
|
||||||
|
|
||||||
###### Auto generated by spf13/cobra on 14-Feb-2022
|
###### Auto generated by spf13/cobra on 15-Feb-2022
|
||||||
|
|||||||
@@ -33,4 +33,4 @@ hrp run $path... [flags]
|
|||||||
|
|
||||||
* [hrp](hrp.md) - One-stop solution for HTTP(S) testing.
|
* [hrp](hrp.md) - One-stop solution for HTTP(S) testing.
|
||||||
|
|
||||||
###### Auto generated by spf13/cobra on 14-Feb-2022
|
###### Auto generated by spf13/cobra on 15-Feb-2022
|
||||||
|
|||||||
@@ -16,4 +16,4 @@ hrp startproject $project_name [flags]
|
|||||||
|
|
||||||
* [hrp](hrp.md) - One-stop solution for HTTP(S) testing.
|
* [hrp](hrp.md) - One-stop solution for HTTP(S) testing.
|
||||||
|
|
||||||
###### Auto generated by spf13/cobra on 14-Feb-2022
|
###### Auto generated by spf13/cobra on 15-Feb-2022
|
||||||
|
|||||||
@@ -48,7 +48,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"check": "headers.\"Content-Type\"",
|
"check": "headers.\"Content-Type\"",
|
||||||
"assert": "starts_with",
|
"assert": "startswith",
|
||||||
"expect": "application/json"
|
"expect": "application/json"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ teststeps:
|
|||||||
expect: 200
|
expect: 200
|
||||||
msg: check response status code
|
msg: check response status code
|
||||||
- check: headers."Content-Type"
|
- check: headers."Content-Type"
|
||||||
assert: starts_with
|
assert: startswith
|
||||||
expect: application/json
|
expect: application/json
|
||||||
- check: body.args.foo1
|
- check: body.args.foo1
|
||||||
assert: length_equals
|
assert: length_equals
|
||||||
|
|||||||
@@ -58,9 +58,11 @@ func TestCaseExtractStepAssociation(t *testing.T) {
|
|||||||
WithHeaders(map[string]string{"User-Agent": "$agent"}).
|
WithHeaders(map[string]string{"User-Agent": "$agent"}).
|
||||||
Extract().
|
Extract().
|
||||||
WithJmesPath("status_code", "statusCode").
|
WithJmesPath("status_code", "statusCode").
|
||||||
|
WithJmesPath("headers.\"Content-Type\"", "contentType").
|
||||||
WithJmesPath("body.args.foo1", "varFoo1").
|
WithJmesPath("body.args.foo1", "varFoo1").
|
||||||
Validate().
|
Validate().
|
||||||
AssertEqual("$statusCode", 200, "check status code").
|
AssertEqual("$statusCode", 200, "check status code").
|
||||||
|
AssertEqual("$contentType", "application/json; charset=utf-8", "check header Content-Type").
|
||||||
AssertEqual("$varFoo1", "bar1", "check args foo1").
|
AssertEqual("$varFoo1", "bar1", "check args foo1").
|
||||||
AssertEqual("body.args.foo2", "bar2", "check args foo2").
|
AssertEqual("body.args.foo2", "bar2", "check args foo2").
|
||||||
AssertEqual("body.headers.\"user-agent\"", "HttpRunnerPlus", "check header user agent"),
|
AssertEqual("body.headers.\"user-agent\"", "HttpRunnerPlus", "check header user agent"),
|
||||||
|
|||||||
@@ -1,81 +0,0 @@
|
|||||||
{
|
|
||||||
"config": {
|
|
||||||
"name": "request methods testcase: validate with parameters",
|
|
||||||
"base_url": "https://httpbingo.bytedance.net"
|
|
||||||
},
|
|
||||||
"teststeps": [
|
|
||||||
{
|
|
||||||
"name": "get with params",
|
|
||||||
"request": {
|
|
||||||
"method": "GET",
|
|
||||||
"url": "/get",
|
|
||||||
"params": {
|
|
||||||
"a": 1,
|
|
||||||
"foo": "I'm a happy guy"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"validate": [
|
|
||||||
{
|
|
||||||
"check": "body.args.a",
|
|
||||||
"assert": "eq",
|
|
||||||
"expect": "1",
|
|
||||||
"msg": "check argument a"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"check": "status_code",
|
|
||||||
"assert": "lt",
|
|
||||||
"expect": 201,
|
|
||||||
"msg": "check status code"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"check": "status_code",
|
|
||||||
"assert": "gt",
|
|
||||||
"expect": 199,
|
|
||||||
"msg": "check status code"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"check": "status_code",
|
|
||||||
"assert": "ge",
|
|
||||||
"expect": 200,
|
|
||||||
"msg": "check status code"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"check": "status_code",
|
|
||||||
"assert": "le",
|
|
||||||
"expect": 200,
|
|
||||||
"msg": "check status code"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"check": "status_code",
|
|
||||||
"assert": "ne",
|
|
||||||
"expect": 199,
|
|
||||||
"msg": "check status code"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"check": "body.args.foo",
|
|
||||||
"assert": "contains",
|
|
||||||
"expect": "happy",
|
|
||||||
"msg": "check status code"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"check": "body.args.foo",
|
|
||||||
"assert": "type_match",
|
|
||||||
"expect": "string",
|
|
||||||
"msg": "check status code"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"check": "body.args.foo",
|
|
||||||
"assert": "starts_with",
|
|
||||||
"expect": "I'm",
|
|
||||||
"msg": "check status code"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"check": "body.args.foo",
|
|
||||||
"assert": "type_match",
|
|
||||||
"expect": "string",
|
|
||||||
"msg": "check status code"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -20,6 +20,7 @@ func TestCaseBasicRequest(t *testing.T) {
|
|||||||
}).
|
}).
|
||||||
Validate().
|
Validate().
|
||||||
AssertEqual("status_code", 200, "check status code").
|
AssertEqual("status_code", 200, "check status code").
|
||||||
|
AssertEqual("headers.\"Content-Type\"", "application/json; charset=utf-8", "check header Content-Type").
|
||||||
AssertEqual("body.args.foo1", "bar1", "check args foo1").
|
AssertEqual("body.args.foo1", "bar1", "check args foo1").
|
||||||
AssertEqual("body.args.foo2", "bar2", "check args foo2"),
|
AssertEqual("body.args.foo2", "bar2", "check args foo2"),
|
||||||
hrp.NewStep("post raw text").
|
hrp.NewStep("post raw text").
|
||||||
|
|||||||
@@ -24,8 +24,9 @@ func TestCaseValidateStep(t *testing.T) {
|
|||||||
Extract().
|
Extract().
|
||||||
WithJmesPath("body.args.foo1", "varFoo1").
|
WithJmesPath("body.args.foo1", "varFoo1").
|
||||||
Validate().
|
Validate().
|
||||||
AssertEqual("status_code", "$expectedStatusCode", "check status code"). // assert status code
|
AssertEqual("status_code", "$expectedStatusCode", "check status code"). // assert status code
|
||||||
AssertEqual("body.args.foo1", "bar1", "check args foo1"). // assert response json body with jmespath
|
AssertEqual("headers.\"Content-Type\"", "application/json; charset=utf-8", "check header Content-Type"). // assert response header, with double quotes
|
||||||
|
AssertEqual("body.args.foo1", "bar1", "check args foo1"). // assert response json body with jmespath
|
||||||
AssertEqual("body.args.foo2", "bar2", "check args foo2").
|
AssertEqual("body.args.foo2", "bar2", "check args foo2").
|
||||||
AssertEqual("body.headers.\"user-agent\"", "HttpRunnerPlus", "check header user agent"),
|
AssertEqual("body.headers.\"user-agent\"", "HttpRunnerPlus", "check header user agent"),
|
||||||
hrp.NewStep("get with params").
|
hrp.NewStep("get with params").
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ func TestCaseConfigVariables(t *testing.T) {
|
|||||||
WithHeaders(map[string]string{"User-Agent": "$agent"}).
|
WithHeaders(map[string]string{"User-Agent": "$agent"}).
|
||||||
Validate().
|
Validate().
|
||||||
AssertEqual("status_code", "$expectedStatusCode", "check status code").
|
AssertEqual("status_code", "$expectedStatusCode", "check status code").
|
||||||
|
AssertEqual("headers.\"Content-Type\"", "application/json; charset=utf-8", "check header Content-Type").
|
||||||
AssertEqual("body.args.foo1", "bar1", "check args foo1").
|
AssertEqual("body.args.foo1", "bar1", "check args foo1").
|
||||||
AssertEqual("body.args.foo2", "bar2", "check args foo2").
|
AssertEqual("body.args.foo2", "bar2", "check args foo2").
|
||||||
AssertEqual("body.headers.\"user-agent\"", "HttpRunnerPlus", "check header user agent"),
|
AssertEqual("body.headers.\"user-agent\"", "HttpRunnerPlus", "check header user agent"),
|
||||||
@@ -51,6 +52,7 @@ func TestCaseStepVariables(t *testing.T) {
|
|||||||
WithHeaders(map[string]string{"User-Agent": "$agent"}).
|
WithHeaders(map[string]string{"User-Agent": "$agent"}).
|
||||||
Validate().
|
Validate().
|
||||||
AssertEqual("status_code", "$expectedStatusCode", "check status code").
|
AssertEqual("status_code", "$expectedStatusCode", "check status code").
|
||||||
|
AssertEqual("headers.\"Content-Type\"", "application/json; charset=utf-8", "check header Content-Type").
|
||||||
AssertEqual("body.args.foo1", "bar1", "check args foo1").
|
AssertEqual("body.args.foo1", "bar1", "check args foo1").
|
||||||
AssertEqual("body.args.foo2", "bar2", "check args foo2").
|
AssertEqual("body.args.foo2", "bar2", "check args foo2").
|
||||||
AssertEqual("body.headers.\"user-agent\"", "HttpRunnerPlus", "check header user agent"),
|
AssertEqual("body.headers.\"user-agent\"", "HttpRunnerPlus", "check header user agent"),
|
||||||
@@ -84,6 +86,7 @@ func TestCaseOverrideConfigVariables(t *testing.T) {
|
|||||||
WithHeaders(map[string]string{"User-Agent": "$agent"}).
|
WithHeaders(map[string]string{"User-Agent": "$agent"}).
|
||||||
Validate().
|
Validate().
|
||||||
AssertEqual("status_code", "$expectedStatusCode", "check status code").
|
AssertEqual("status_code", "$expectedStatusCode", "check status code").
|
||||||
|
AssertEqual("headers.\"Content-Type\"", "application/json; charset=utf-8", "check header Content-Type").
|
||||||
AssertEqual("body.args.foo1", "bar1", "check args foo1").
|
AssertEqual("body.args.foo1", "bar1", "check args foo1").
|
||||||
AssertEqual("body.args.foo2", "bar2", "check args foo2").
|
AssertEqual("body.args.foo2", "bar2", "check args foo2").
|
||||||
AssertEqual("body.headers.\"user-agent\"", "HttpRunnerPlus", "check header user agent"),
|
AssertEqual("body.headers.\"user-agent\"", "HttpRunnerPlus", "check header user agent"),
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ var Assertions = map[string]func(t assert.TestingT, actual interface{}, expected
|
|||||||
"contains": assert.Contains,
|
"contains": assert.Contains,
|
||||||
"type_match": assert.IsType,
|
"type_match": assert.IsType,
|
||||||
// custom assertions
|
// custom assertions
|
||||||
"starts_with": StartsWith,
|
"startswith": StartsWith,
|
||||||
"ends_with": EndsWith,
|
"endswith": EndsWith,
|
||||||
"len_eq": EqualLength,
|
"len_eq": EqualLength,
|
||||||
"length_equals": EqualLength,
|
"length_equals": EqualLength,
|
||||||
"length_equal": EqualLength,
|
"length_equal": EqualLength,
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ var (
|
|||||||
WithCookies(map[string]string{"user": "debugtalk"}).
|
WithCookies(map[string]string{"user": "debugtalk"}).
|
||||||
Validate().
|
Validate().
|
||||||
AssertEqual("status_code", 200, "check status code").
|
AssertEqual("status_code", 200, "check status code").
|
||||||
|
AssertEqual("headers.\"Content-Type\"", "application/json; charset=utf-8", "check header Content-Type").
|
||||||
AssertEqual("body.args.foo1", "bar1", "check param foo1").
|
AssertEqual("body.args.foo1", "bar1", "check param foo1").
|
||||||
AssertEqual("body.args.foo2", "bar2", "check param foo2")
|
AssertEqual("body.args.foo2", "bar2", "check param foo2")
|
||||||
stepPOSTData = NewStep("post form data").
|
stepPOSTData = NewStep("post form data").
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ func (s *StepRequestValidation) AssertRegexp(jmesPath string, expected interface
|
|||||||
func (s *StepRequestValidation) AssertStartsWith(jmesPath string, expected interface{}, msg string) *StepRequestValidation {
|
func (s *StepRequestValidation) AssertStartsWith(jmesPath string, expected interface{}, msg string) *StepRequestValidation {
|
||||||
v := Validator{
|
v := Validator{
|
||||||
Check: jmesPath,
|
Check: jmesPath,
|
||||||
Assert: "starts_with",
|
Assert: "startswith",
|
||||||
Expect: expected,
|
Expect: expected,
|
||||||
Message: msg,
|
Message: msg,
|
||||||
}
|
}
|
||||||
@@ -137,7 +137,7 @@ func (s *StepRequestValidation) AssertStartsWith(jmesPath string, expected inter
|
|||||||
func (s *StepRequestValidation) AssertEndsWith(jmesPath string, expected interface{}, msg string) *StepRequestValidation {
|
func (s *StepRequestValidation) AssertEndsWith(jmesPath string, expected interface{}, msg string) *StepRequestValidation {
|
||||||
v := Validator{
|
v := Validator{
|
||||||
Check: jmesPath,
|
Check: jmesPath,
|
||||||
Assert: "ends_with",
|
Assert: "endswith",
|
||||||
Expect: expected,
|
Expect: expected,
|
||||||
Message: msg,
|
Message: msg,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user