Files
httprunner/tests/data/demo_template_sets.yml
debugtalk f41729094a refactor variable context:
1, variable context has two level, testset and testcase;
2, testset level variables can be used in whole test suite, while testcase level variables can only be used in testcase;
3, when variable binds with functions, the funtions will be called and the result will be set to the variable.
2017-07-20 22:43:18 +08:00

51 lines
1.7 KiB
YAML

- config:
name: "create user testsets."
requires:
- random
- string
- hashlib
function_binds:
gen_random_string: "lambda str_len: ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(str_len))"
gen_md5: "lambda *str_args: hashlib.md5(''.join(str_args).encode('utf-8')).hexdigest()"
variable_binds:
- TOKEN: debugtalk
request:
base_url: http://127.0.0.1:5000
- test:
name: create user which does not exist
variable_binds:
- data: '{"name": "user", "password": "123456"}'
- random: ${gen_random_string(5)}
- authorization: ${gen_md5($TOKEN, $data, $random)}
request:
url: /api/users/1000
method: POST
headers:
Content-Type: application/json
authorization: $authorization
random: $random
data: $data
validators:
- {"check": "status_code", "comparator": "eq", "expected": 201}
- {"check": "content.success", "comparator": "eq", "expected": true}
- test:
name: create user which does exist
variable_binds:
- data: '{"name": "user", "password": "123456"}'
- random: ${gen_random_string(5)}
- authorization: ${gen_md5($TOKEN, $data, $random)}
- expected_status_code: 500
request:
url: /api/users/1000
method: POST
headers:
Content-Type: application/json
authorization: $authorization
random: $random
data: $data
validators:
- {"check": "status_code", "comparator": "eq", "expected": 500}
- {"check": "content.success", "comparator": "eq", "expected": false}