Files
httprunner/tests/data/demo_testset_template_lambda_functions.yml
2017-08-01 11:33:31 +08:00

74 lines
2.2 KiB
YAML

- config:
name: "create user testsets."
requires:
- random
- string
- hashlib
- hmac
function_binds:
gen_random_string_lambda: "lambda str_len: ''.join(
random.choice(string.ascii_letters + string.digits) for _ in range(str_len))"
get_sign_lambda: "lambda *args: hmac.new(
'DebugTalk'.encode('ascii'),
''.join(args).encode('ascii'),
hashlib.sha1).hexdigest()"
variable_binds:
- user_agent: 'iOS/10.3'
- device_sn: ${gen_random_string_lambda(15)}
- os_platform: 'ios'
- app_version: '2.8.6'
request:
base_url: http://127.0.0.1:5000
headers:
Content-Type: application/json
device_sn: $device_sn
- test:
name: get token
request:
url: /api/get-token
method: POST
headers:
user_agent: $user_agent
device_sn: $device_sn
os_platform: $os_platform
app_version: $app_version
json:
sign: ${get_sign_lambda($user_agent, $device_sn, $os_platform, $app_version)}
extract_binds:
- token: content.token
validators:
- {"check": "status_code", "comparator": "eq", "expected": 200}
- {"check": "content.token", "comparator": "len_eq", "expected": 16}
- test:
name: create user which does not exist
variable_binds:
- user_name: "user1"
- user_password: "123456"
request:
url: /api/users/1000
method: POST
headers:
token: $token
json:
name: $user_name
password: $user_password
validators:
- {"check": "status_code", "comparator": "eq", "expected": 201}
- {"check": "content.success", "comparator": "eq", "expected": true}
- test:
name: create user which does not exist
request:
url: /api/users/1000
method: POST
headers:
token: $token
json:
name: "user1"
password: "123456"
validators:
- {"check": "status_code", "comparator": "eq", "expected": 500}
- {"check": "content.success", "comparator": "eq", "expected": false}