/
request_test.py
102 lines (86 loc) · 2.98 KB
/
request_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# -*- coding: utf-8 -*-
import time
import datetime
import json
import arrow
import requests
from requests.auth import HTTPBasicAuth, HTTPDigestAuth
IP = '127.0.0.1'
PORT = 5000
def send_get(url,headers = {'content-type': 'application/json'}):
"""POST请求"""
r = requests.get(url, headers=headers,
auth=HTTPDigestAuth('kakou', 'pingworker'))
return r
def auth_test(url):
headers = {'Authorization': 'Digest kakou="pingworker"',
'content-type': 'application/json'}
r = requests.get(url, headers=headers)
return r
def hbc_post():
data = {
'jgsj': str(datetime.datetime.now()),
'hphm': '粤L12345',
'kkdd_id': '441322004','hpys_id': 2,'fxbh_id': 4,'cdbh': 5,
'imgurl': 'http://localhost/imgareaselect/imgs/1.jpg'#,'imgpath': u'c:\\123.jpg'
}
headers = {'content-type': 'application/json'}
url = 'http://127.0.0.1:8098/v1/hbc'
r = requests.post(url, headers=headers,data=json.dumps(data))
return r
def hbc_get():
#url = 'http://127.0.0.1:8098/hbc/2015-09-09 17:18:27/粤L54321/441322004'
url = 'http://127.0.0.1:8098'
headers = {'content-type': 'application/json'}
return requests.get(url, headers=headers)
def ab_test():
t1 = time.time()
for i in range(50):
r = hbc_get()
print time.time()-t1
def token_test():
#auth = HTTPBasicAuth('admin','gdsx27677221')
headers = {'content-type': 'application/json'}
url = 'http://%s:%s/token' % (IP, PORT)
data = {'username': 'test1', 'password': 'test12345'}
return requests.post(url, headers=headers, data=json.dumps(data))
def scope_get(token):
url = 'http://localhost:8098/scope/'
headers = {'content-type': 'application/json',
'access_token': token}
return requests.get(url, headers=headers)
def test_kakou_post():
url = 'http://{0}:{1}/kakou'.format(IP, PORT)
headers = {'content-type': 'application/json'}
data = [
{
'jgsj': arrow.now().format('YYYY-MM-DD HH:mm:ss'),
'hphm': '粤L70939',
'kkdd_id': '441302004',
'hpys_id': '0',
'fxbh': 'IN',
'cdbh':4,
'img_path': 'http:///img/123.jpg'
},
{
'jgsj': arrow.now().format('YYYY-MM-DD HH:mm:ss'),
'hphm': '粤L12345',
'kkdd_id': '441302004',
'hpys_id': '0',
'fxbh': 'IN',
'cdbh': 4,
'img_path': 'http:///img/123.jpg',
'cllx': 'K41'
}
]
return requests.post(url, headers=headers, data=json.dumps(data))
if __name__ == '__main__': # pragma nocover
token = 'eyJhbGciOiJIUzI1NiIsImV4cCI6MTQ0Mjg2MDMwNywiaWF0IjoxNDQyODUzMTA3fQ.eyJzY29wZSI6WyJzY29wZV9nZXQiLCJoemhiY19nZXQiXSwidWlkIjoyM30.0TTL1Xp0Ft6nKRSQbqNZemlPDy7E9sL0vsVZteYYugA'
#ab_test()
#r = token_test()
#r = auth_test(url)
r = test_kakou_post()
#r = test_hbc_post(token)
print r.headers
print r.status_code
print r.text