-
Notifications
You must be signed in to change notification settings - Fork 0
/
AskhomeworkInterfaceTest.py
74 lines (64 loc) · 2.37 KB
/
AskhomeworkInterfaceTest.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
# @File : AskhomeworkInterfaceTest.py
# @Author: LiuXingsheng
# @Date : 2019/3/16
# @Desc :
import requests, demjson
# REQUESTDOMAIN = 'http://test.eebbk.net/ask-homework'
# REQUESTDOMAIN = 'http://ite.eebbk.net/ask-homework'
REQUESTDOMAIN = 'http://askhomework.eebbk.net'
def getMachineAnswerSwitch(machienId):
"""
获取答案锁
:param machienId:
:return:
"""
url = REQUESTDOMAIN + '/service/answerswitch/getMachineAnswerSwitch'
params = {'machineId': machienId}
result = requests.get(url=url, params=params, headers=getHeaders(machienId))
print(result.text)
content = demjson.decode(result.text)
if 'answerSwitch' in result.text:
switch = content['data']['answerSwitch']
if switch == 0:
newSwitch = 1
else:
newSwitch = 0
return (True, switch, newSwitch, machienId)
else:
print('请求错误')
return False
def uploadMachineAnswerSwitch(tupleresponse):
"""
修改答案锁并查看是否修改成功
:param tupleresponse:
:return:
"""
status = tupleresponse[0]
originalswitch = tupleresponse[1]
newswitch = tupleresponse[2]
machineId = tupleresponse[3]
url = REQUESTDOMAIN + '/service/answerswitch/uploadMachineAnswerSwitch'
params = {'machineId': machineId, 'switchValue': newswitch}
if status == True:
# 此处的修改答案锁开关无需判断取值,只需查看后一次的查询接口是否和之前的状态只发生变化
requests.post(url=url, data=params, headers=getHeaders(machineId))
tuplecheck = getMachineAnswerSwitch(machineId)
if not tupleresponse:
print('修改状态失败')
else:
# 对比修改答案的前后,两个开关状态不一致即可,0或者是1
if tuplecheck[1] != originalswitch:
print('修改成功')
else:
print('修改失败')
else:
print('获取状态失败')
def getHeaders(machineId):
return {'machineId': machineId, 'accountId': '4051922', 'apkPackageName': 'com.eebbk.askhomework',
'apkVersionCode': '1.0.0', 'deviceModel': 'H20', 'deviceOSVersion': 'V1.0.0_180409'}
def main():
machineId = '700H38300018B'
tupleresoinse = getMachineAnswerSwitch(machineId)
uploadMachineAnswerSwitch(tupleresoinse)
if __name__ == '__main__':
main()