update docs

This commit is contained in:
debugtalk
2018-02-08 17:46:44 +08:00
parent 804bfd48c7
commit dab401e07a
4 changed files with 4 additions and 82 deletions

View File

@@ -1,22 +0,0 @@
# Comparator
| comparator | Description | A(check), B(expected) | examples |
|:------------:|-----------|------------------------------------|-----------|
| `eq`, `==` | value is equal | A == B | 9 eq 9 |
| `lt` | less than | A < B | 7 lt 8 |
| `le` | less than or equals | A <= B | 7 le 8, 8 le 8 |
| `gt` | greater than | A > B | 8 gt 7 |
| `ge` | greater than or equals | A >= B | 8 ge 7, 8 ge 8 |
| `ne` | not equals | A != B | 6 ne 9 |
| `str_eq` | string equals | str(A) == str(B) | 123 str_eq '123' |
| `len_eq`, `count_eq` | length or count equals | len(A) == B | 'abc' len_eq 3<br/>[1,2] len_eq 2 |
| `len_gt`, `count_gt` | length greater than | len(A) > B | 'abc' len_gt 2<br/>[1,2,3] len_gt 2 |
| `len_ge`, `count_ge` | length greater than or equals | len(A) >= B | 'abc' len_ge 3<br/>[1,2,3] len_gt 3 |
| `len_lt`, `count_lt` | length less than | len(A) < B | 'abc' len_lt 4<br/>[1,2,3] len_lt 4 |
| `len_le`, `count_le` | length less than or equals | len(A) <= B | 'abc' len_le 3<br/>[1,2,3] len_le 3 |
| `contains` | contains | B in A | [1, 2] contains 1<br/>'abc' contains 'a' |
| `contained_by` | contained by | A in B | 1 contained_by [1,2]<br/>'a' contained_by 'abc' |
| `type` | type of A is instance of B | isinstance(A, B) | 123 type 'int' |
| `regex` | regex matches | re.match(B, A) | 'abcdef' regex 'a\w+d' |
| `startswith` | starts with | A.startswith(B) is True | 'abc' startswith 'ab' |
| `endswith` | ends with | A.endswith(B) is True | 'abc' endswith 'bc' |

View File

@@ -1,58 +0,0 @@
# Extraction and Validation
Suppose we get the following HTTP response.
```text
# status code: 200
# response headers
{
"Content-Type": "application/json"
}
# response body content
{
"success": False,
"person": {
"name": {
"first_name": "Leo",
"last_name": "Lee",
},
"age": 29,
"cities": ["Guangzhou", "Shenzhen"]
}
}
```
In `extract` and `validate`, we can do chain operation to extract data field in HTTP response.
For instance, if we want to get `Content-Type` in response headers, then we can specify `headers.content-type`; if we want to get `first_name` in response content, we can specify `content.person.name.first_name`.
There might be slight difference on list, cos we can use index to locate list item. For example, `Guangzhou` in response content can be specified by `content.person.cities.0`.
```text
# get status code
status_code
# get headers field
headers.content-type
# get content field
body.success
content.success
text.success
content.person.name.first_name
content.person.cities.1
```
```yaml
extract:
- content_type: headers.content-type
- first_name: content.person.name.first_name
validate:
- {"check": "status_code", "comparator": "eq", "expected": 200}
- {"check": "headers.content-type", "expected": "application/json"}
- {"check": "headers.content-length", "comparator": "gt", "expected": 40}
- {"check": "content.success", "comparator": "eq", "expected": True}
- {"check": "content.token", "comparator": "len_eq", "expected": 16}
```

View File

@@ -25,6 +25,8 @@
extract:
- token: content.token
validate:
- eq: ["status_code", 200]
- len_eq: ["content.token", 16]
- {"check": "status_code", "comparator": "eq", "expect": 200}
- {"check": "content.token", "comparator": "len_eq", "expect": 16}

View File

@@ -72,7 +72,7 @@ class Runner(object):
@param (dict) testcase_dict
{
"name": "testcase description",
"skip": Fasle,
"skip": "skip this test unconditionally",
"times": 3,
"requires": [], # optional, override
"function_binds": {}, # optional, override
@@ -87,7 +87,7 @@ class Runner(object):
},
"body": '{"name": "user", "password": "123456"}'
},
"extract": [], # optional
"extract": [], # optional
"validate": [], # optional
"setup": [], # optional
"teardown": [] # optional