mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 11:29:48 +08:00
add quickstart docs
This commit is contained in:
0
examples/__init__.py
Normal file
0
examples/__init__.py
Normal file
30
examples/quickstart-demo-rev-0.yml
Normal file
30
examples/quickstart-demo-rev-0.yml
Normal file
@@ -0,0 +1,30 @@
|
||||
- test:
|
||||
name: get token
|
||||
request:
|
||||
url: http://127.0.0.1:5000/api/get-token
|
||||
method: POST
|
||||
headers:
|
||||
user_agent: iOS/10.3
|
||||
device_sn: 9TN6O2Bn1vzfybF
|
||||
os_platform: ios
|
||||
app_version: 2.8.6
|
||||
json:
|
||||
sign: 19067cf712265eb5426db8d3664026c1ccea02b9
|
||||
validators:
|
||||
- {"check": "status_code", "comparator": "eq", "expected": 200}
|
||||
- {"check": "content.token", "comparator": "len_eq", "expected": 16}
|
||||
|
||||
- test:
|
||||
name: create user which does not exist
|
||||
request:
|
||||
url: http://127.0.0.1:5000/api/users/1000
|
||||
method: POST
|
||||
headers:
|
||||
device_sn: 9TN6O2Bn1vzfybF
|
||||
token: F8prvGryC5beBr4g
|
||||
json:
|
||||
name: "user1"
|
||||
password: "123456"
|
||||
validators:
|
||||
- {"check": "status_code", "comparator": "eq", "expected": 201}
|
||||
- {"check": "content.success", "comparator": "eq", "expected": true}
|
||||
32
examples/quickstart-demo-rev-1.yml
Normal file
32
examples/quickstart-demo-rev-1.yml
Normal file
@@ -0,0 +1,32 @@
|
||||
- test:
|
||||
name: get token
|
||||
request:
|
||||
url: http://127.0.0.1:5000/api/get-token
|
||||
method: POST
|
||||
headers:
|
||||
user_agent: iOS/10.3
|
||||
device_sn: 9TN6O2Bn1vzfybF
|
||||
os_platform: ios
|
||||
app_version: 2.8.6
|
||||
json:
|
||||
sign: 19067cf712265eb5426db8d3664026c1ccea02b9
|
||||
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
|
||||
request:
|
||||
url: http://127.0.0.1:5000/api/users/1001
|
||||
method: POST
|
||||
headers:
|
||||
device_sn: 9TN6O2Bn1vzfybF
|
||||
token: $token
|
||||
json:
|
||||
name: "user1"
|
||||
password: "123456"
|
||||
validators:
|
||||
- {"check": "status_code", "comparator": "eq", "expected": 201}
|
||||
- {"check": "content.success", "comparator": "eq", "expected": true}
|
||||
39
examples/quickstart-demo-rev-2.yml
Normal file
39
examples/quickstart-demo-rev-2.yml
Normal file
@@ -0,0 +1,39 @@
|
||||
- test:
|
||||
name: get token
|
||||
import_module_functions:
|
||||
- examples.utils
|
||||
variable_binds:
|
||||
- user_agent: 'iOS/10.3'
|
||||
- device_sn: ${gen_random_string(15)}
|
||||
- os_platform: 'ios'
|
||||
- app_version: '2.8.6'
|
||||
request:
|
||||
url: http://127.0.0.1:5000/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($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
|
||||
request:
|
||||
url: http://127.0.0.1:5000/api/users/1000
|
||||
method: POST
|
||||
headers:
|
||||
device_sn: $device_sn
|
||||
token: $token
|
||||
json:
|
||||
name: "user1"
|
||||
password: "123456"
|
||||
validators:
|
||||
- {"check": "status_code", "comparator": "eq", "expected": 201}
|
||||
- {"check": "content.success", "comparator": "eq", "expected": true}
|
||||
45
examples/quickstart-demo-rev-3.yml
Normal file
45
examples/quickstart-demo-rev-3.yml
Normal file
@@ -0,0 +1,45 @@
|
||||
- config:
|
||||
name: "smoketest for CRUD users."
|
||||
import_module_functions:
|
||||
- examples.utils
|
||||
variable_binds:
|
||||
- device_sn: ${gen_random_string(15)}
|
||||
request:
|
||||
base_url: http://127.0.0.1:5000
|
||||
headers:
|
||||
device_sn: $device_sn
|
||||
|
||||
- test:
|
||||
name: get token
|
||||
variable_binds:
|
||||
- user_agent: 'iOS/10.3'
|
||||
- os_platform: 'ios'
|
||||
- app_version: '2.8.6'
|
||||
request:
|
||||
url: /api/get-token
|
||||
method: POST
|
||||
headers:
|
||||
user_agent: $user_agent
|
||||
os_platform: $os_platform
|
||||
app_version: $app_version
|
||||
json:
|
||||
sign: ${get_sign($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
|
||||
request:
|
||||
url: /api/users/1000
|
||||
method: POST
|
||||
headers:
|
||||
token: $token
|
||||
json:
|
||||
name: "user1"
|
||||
password: "123456"
|
||||
validators:
|
||||
- {"check": "status_code", "comparator": "eq", "expected": 201}
|
||||
- {"check": "content.success", "comparator": "eq", "expected": true}
|
||||
22
examples/utils.py
Normal file
22
examples/utils.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import hashlib
|
||||
import hmac
|
||||
import random
|
||||
import string
|
||||
|
||||
SECRET_KEY = "DebugTalk"
|
||||
|
||||
def gen_random_string(str_len):
|
||||
random_char_list = []
|
||||
for _ in range(str_len):
|
||||
random_char = random.choice(string.ascii_letters + string.digits)
|
||||
random_char_list.append(random_char)
|
||||
|
||||
random_string = ''.join(random_char_list)
|
||||
return random_string
|
||||
|
||||
def get_sign(*args):
|
||||
content = ''.join(args).encode('ascii')
|
||||
sign_key = SECRET_KEY.encode('ascii')
|
||||
sign = hmac.new(sign_key, content, hashlib.sha1).hexdigest()
|
||||
return sign
|
||||
|
||||
Reference in New Issue
Block a user