PcPost.py
3.01 KB
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
from atdd.ATDDCase import ATDDCase
import hashlib
import json
class PcPost(ATDDCase):
# 多企业登录
def get_enterprise(self, data):
result = data['result']
if isinstance(result, list):
user = result[0]
if len(result) > 1:
print("选择企业:", user['enterpriseInfo']['epName'])
return user
def do_login(self, host, mobile=None, pwd=None, domain=None):
assert host is not None, "登录 host 必须设置"
assert (domain is not None) or (
mobile is not None and pwd is not None), 'domain 和 mobile/pwd 不能同时为空'
if mobile is None or pwd is None:
print('没有手机或密码,跳过登陆阶段')
return
check_mobile_pwd_url = self.host + '/comm/Public/Apicp/Admin/ChkMobilePwd?_identifier=common'
print("校验登录账号密码", check_mobile_pwd_url)
pwd = hashlib.md5(pwd.encode('utf-8')).hexdigest()
response = self.post(
check_mobile_pwd_url,
{
'mobile': mobile,
'passwd': pwd
}
)
assert response.status_code == 200, "检测手机和密码" + response.text
data = response.json()
assert data['errcode'] == 0, json.dumps(data, indent=2, sort_keys=False, ensure_ascii=False)
user = self.get_enterprise(data)
assert user is not None, '选择企业管理员失败'
self.domain = user['enterpriseInfo']['epEnumber']
logintoken = user['adminerInfo']['loginToken']
login_url = self.host + '/' + self.domain +'/Public/Apicp/Admin/Login?_identifier=common'
print("开始登录", login_url)
response = self.post(
login_url,
{
'loginToken': logintoken,
'passwd': pwd
}
)
assert response.status_code == 200, "登陆请求失败" + response.text
data = response.json()
assert data['errcode'] == 0, json.dumps(data, indent=2, sort_keys=False, ensure_ascii=False)
return data
# 后端接口模板-正常
def PcPost(self, interfaceUrl, data=None, **options):
self.interfaceUrl = interfaceUrl
self.data = data
url = self.host + '/' + self.domain + self.interfaceUrl
r = self.post(url, self.data, **options)
self.assertEqual(200, r.status_code)
result = json.loads(r.text)
errcode = result['errcode']
self.assertEqual(0, errcode)
return result
# 后端接口模板-异常判断
def PcPostAbnormal(self, interfaceUrl, data=None, code = None,**options):
self.interfaceUrl = interfaceUrl
self.data = data
self.code = code
url = self.host + '/' + self.domain + self.interfaceUrl
r = self.post(url, self.data, **options)
self.assertEqual(200, r.status_code)
result = json.loads(r.text)
errcode = result['errcode']
self.assertEqual(code, errcode)
return result