You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.6 KiB
48 lines
1.6 KiB
|
2 weeks ago
|
# -*- coding: utf-8 -*-
|
||
|
|
import urllib.request as u
|
||
|
|
import urllib.error
|
||
|
|
import json
|
||
|
|
|
||
|
|
API = 'http://localhost:8080'
|
||
|
|
USER_ID = '739564171091247104'
|
||
|
|
|
||
|
|
|
||
|
|
def call(method, path, token=None, jbody=None, form=None):
|
||
|
|
data = None
|
||
|
|
headers = {}
|
||
|
|
if token:
|
||
|
|
headers['Authorization'] = 'Bearer ' + token
|
||
|
|
if jbody is not None:
|
||
|
|
data = json.dumps(jbody, ensure_ascii=False).encode('utf-8')
|
||
|
|
headers['Content-Type'] = 'application/json; charset=utf-8'
|
||
|
|
if form is not None:
|
||
|
|
data = '&'.join(f'{k}={v}' for k, v in form.items()).encode('utf-8')
|
||
|
|
headers['Content-Type'] = 'application/x-www-form-urlencoded'
|
||
|
|
req = u.Request(API + path, data=data, headers=headers, method=method)
|
||
|
|
try:
|
||
|
|
with u.urlopen(req, timeout=15) as r:
|
||
|
|
return r.status, json.loads(r.read().decode('utf-8'))
|
||
|
|
except urllib.error.HTTPError as e:
|
||
|
|
body = e.read().decode('utf-8', 'replace')
|
||
|
|
return e.code, body
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == '__main__':
|
||
|
|
_, tok_res = call('GET', f'/api/auth/debug/token?userId={USER_ID}')
|
||
|
|
tok = tok_res['data']
|
||
|
|
print('TOKEN len', len(tok))
|
||
|
|
|
||
|
|
st, res = call('POST', '/api/opportunity', tok, jbody={
|
||
|
|
'oppSource': 'opp_source_02',
|
||
|
|
'opportunityName': 'E2E冒烟商机',
|
||
|
|
'partyA': '某甲方公司',
|
||
|
|
'customerName': '意向客户A',
|
||
|
|
'remark': 'python 创建的端到端测试商机',
|
||
|
|
})
|
||
|
|
print('CREATE', st, res)
|
||
|
|
|
||
|
|
st, res = call('POST', '/api/opportunity/page', tok, form={
|
||
|
|
'viewType': 'MINE', 'current': '1', 'size': '20'})
|
||
|
|
print('PAGE', st)
|
||
|
|
print(json.dumps(res, ensure_ascii=False, indent=2)[:1200])
|