test_outCard.py
17.6 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
#coding=utf-8
# @Time : 2021/5/24 9:51
# @Author : Ljq
# @File : test_outCard.py
# @Software: PyCharm
"""
卡片出库测试用例
"""
import unittest
import re
import time
import json
import math
import commons.api.cardStorageIn as cSI
import commons.api.cardStorageOut as cSO
from commons.readConf import readConfig
from commons.api.doLogin import doLogin
class test_outCard(unittest.TestCase):
@classmethod
def setUpClass(cls):
# 获取登录信息和可用headers
rC = readConfig()
cls.cardHost = rC.returnOptionsItems("host", "cardHost")
cls.webHeaders,cls.clientHeaders,cls.userInfo = doLogin().loginUser()
cls.applyUserName = cls.userInfo["data"]["user"]["realName"]
cls.applyUserId = cls.userInfo["data"]["user"]["id"]
cls.applyUserCode = cls.userInfo["data"]["user"]["userName"]
@classmethod
def tearDownClass(cls):
pass
def setUp(self):
time.sleep(2)
# pass
def tearDown(self):
pass
def test_openPage(self):
# 直接打开出库列表
listRes = cSO.getOutPage(cardHost=self.cardHost,webHeaders=self.webHeaders)
print(listRes.json())
assert "200" == listRes.json()["code"],"出库列表查询失败"
def test_outCard_positive(self):
# 先添加入库卡片
faceNum = 3
startCardNo = int(time.strftime("%y%m%d%H%M%S", time.localtime()))
endCardNo = startCardNo + 1
cardFace = cSI.returnFaceValue(resCardFace=cSI.getCardFace(cardHost=self.cardHost, webHeaders=self.webHeaders),faceNum=faceNum)
resSavaCard = cSI.savaCard(cardHost=self.cardHost,webHeaders=self.webHeaders,startCardNo=startCardNo,endCardNo=endCardNo,cardFace=cardFace)
# 出库 ---> 卡片类别获取
cardTypeRes = cSO.getCardType(cardHost=self.cardHost,webHeaders=self.webHeaders)
# 获取用户信息
userInfo = cSO.getUserInfo(cardHost=self.cardHost, webHeaders=self.webHeaders, name=self.applyUserCode,keyword=self.applyUserCode)
assert userInfo.json()["data"][0]["id"] == self.applyUserId, "获取到的用户信息与实际用户信息不匹配"
# 出库 ---> 卡面信息获取
cardFaceB = cSI.returnFaceValue(resCardFace=cSO.getCardFace(cardHost=self.cardHost,webHeaders=self.webHeaders),faceNum=faceNum)
# 出库 ---> 卡片入库卡面与当前卡面对比
for cardNo in range(startCardNo,endCardNo+1):
cardState = cSO.checkCardForOut(cardHost=self.cardHost, webHeaders=self.webHeaders,cardFace=cardFaceB,cardNo=cardNo)
assert cardState.json()["code"] == "200","卡片面校验不通过"
assert cardFace == cardFaceB,"卡面信息断言失败"
# 出库 ---> 卡片出库
cardNos = str(startCardNo) + "," + str(endCardNo)
amount = len([i for i in range(startCardNo,endCardNo+1)])
outCardRes = cSO.cardAddOut(cardHost=self.cardHost,webHeaders=self.webHeaders,cardNos=cardNos,applyUserName=self.applyUserName,applyUserId=self.applyUserId,applyUserCode=self.applyUserCode,amount=amount)
assert outCardRes.json()["code"] == "200","出库失败"
# 出库信息断言
outCardDetail = cSO.getOutCardDetail(cardHost=self.cardHost, webHeaders=self.webHeaders)
assert sorted(outCardDetail) == sorted([str(i) for i in range(startCardNo,endCardNo+1)]), "返回的出库信息与实际出库信息不一致"
def test_searchUser(self):
# 先添加入库卡片
faceNum = 3
startCardNo = int(time.strftime("%y%m%d%H%M%S", time.localtime()))
endCardNo = startCardNo + 1
cardFace = cSI.returnFaceValue(resCardFace=cSI.getCardFace(cardHost=self.cardHost, webHeaders=self.webHeaders),
faceNum=faceNum)
resSavaCard = cSI.savaCard(cardHost=self.cardHost, webHeaders=self.webHeaders, startCardNo=startCardNo,
endCardNo=endCardNo, cardFace=cardFace)
# 出库 ---> 卡片类别获取
cardTypeRes = cSO.getCardType(cardHost=self.cardHost, webHeaders=self.webHeaders)
# 获取用户信息
userInfo = cSO.getUserInfo(cardHost=self.cardHost, webHeaders=self.webHeaders, name=self.applyUserCode,
keyword=self.applyUserCode)
assert userInfo.json()["data"][0]["id"] == self.applyUserId, "获取到的用户信息与实际用户信息不匹配"
# 出库 ---> 卡面信息获取
cardFaceB = cSI.returnFaceValue(resCardFace=cSO.getCardFace(cardHost=self.cardHost, webHeaders=self.webHeaders),
faceNum=faceNum)
# 出库 ---> 卡片入库卡面与当前卡面对比
for cardNo in range(startCardNo, endCardNo + 1):
cardState = cSO.checkCardForOut(cardHost=self.cardHost, webHeaders=self.webHeaders, cardFace=cardFaceB,
cardNo=cardNo)
assert cardState.json()["code"] == "200", "卡片面校验不通过"
assert cardFace == cardFaceB, "卡面信息断言失败"
# 出库 ---> 卡片出库
cardNos = str(startCardNo) + "," + str(endCardNo)
amount = len([i for i in range(startCardNo, endCardNo + 1)])
outCardRes = cSO.cardAddOut(cardHost=self.cardHost, webHeaders=self.webHeaders, cardNos=cardNos,
applyUserName=self.applyUserName, applyUserId=self.applyUserId,
applyUserCode=self.applyUserCode, amount=amount)
assert outCardRes.json()["code"] == "200", "出库失败"
# 根据领取人获取最新的出库记录
listRes = cSO.getOutPage(cardHost=self.cardHost, webHeaders=self.webHeaders,applyUserName=self.applyUserName,
applyUserId=self.applyUserId)
assert self.applyUserName == list(set([i["applyUserName"] for i in listRes.json()["rows"]]))[0],"领取人查询成功"
def test_searchCard(self):
# 先添加入库卡片
faceNum = 3
startCardNo = int(time.strftime("%y%m%d%H%M%S", time.localtime()))
endCardNo = startCardNo + 1
cardFace = cSI.returnFaceValue(resCardFace=cSI.getCardFace(cardHost=self.cardHost, webHeaders=self.webHeaders),
faceNum=faceNum)
resSavaCard = cSI.savaCard(cardHost=self.cardHost, webHeaders=self.webHeaders, startCardNo=startCardNo,
endCardNo=endCardNo, cardFace=cardFace)
# 出库 ---> 卡片类别获取
cardTypeRes = cSO.getCardType(cardHost=self.cardHost, webHeaders=self.webHeaders)
# 获取用户信息
userInfo = cSO.getUserInfo(cardHost=self.cardHost, webHeaders=self.webHeaders, name=self.applyUserCode,
keyword=self.applyUserCode)
assert userInfo.json()["data"][0]["id"] == self.applyUserId, "获取到的用户信息与实际用户信息不匹配"
# 出库 ---> 卡面信息获取
cardFaceB = cSI.returnFaceValue(resCardFace=cSO.getCardFace(cardHost=self.cardHost, webHeaders=self.webHeaders),
faceNum=faceNum)
# 出库 ---> 卡片入库卡面与当前卡面对比
for cardNo in range(startCardNo, endCardNo + 1):
cardState = cSO.checkCardForOut(cardHost=self.cardHost, webHeaders=self.webHeaders, cardFace=cardFaceB,
cardNo=cardNo)
assert cardState.json()["code"] == "200", "卡片面校验不通过"
assert cardFace == cardFaceB, "卡面信息断言失败"
# 出库 ---> 卡片出库
cardNos = str(startCardNo) + "," + str(endCardNo)
amount = len([i for i in range(startCardNo, endCardNo + 1)])
outCardRes = cSO.cardAddOut(cardHost=self.cardHost, webHeaders=self.webHeaders, cardNos=cardNos,
applyUserName=self.applyUserName, applyUserId=self.applyUserId,
applyUserCode=self.applyUserCode, amount=amount)
assert outCardRes.json()["code"] == "200", "出库失败"
# 根据领取人获取最新的出库记录
listRes = cSO.getOutPage(cardHost=self.cardHost, webHeaders=self.webHeaders,cardNo=startCardNo)
assert 1 == len([i for i in listRes.json()["rows"]]),"查询结果不唯一,查询失败"
firstId = listRes.json()["rows"][0]["id"]
resDetail = cSO.getOutListDetail(cardHost=self.cardHost, webHeaders=self.webHeaders, id=firstId)
outCardDetail = re.findall("<ul><li>(.*?)</li></ul>", resDetail.text)
assert str(startCardNo) in outCardDetail,"查询失败"
def test_searchDate(self):
# 先添加入库卡片
faceNum = 3
startCardNo = int(time.strftime("%y%m%d%H%M%S", time.localtime()))
endCardNo = startCardNo + 1
cardFace = cSI.returnFaceValue(resCardFace=cSI.getCardFace(cardHost=self.cardHost, webHeaders=self.webHeaders),
faceNum=faceNum)
resSavaCard = cSI.savaCard(cardHost=self.cardHost, webHeaders=self.webHeaders, startCardNo=startCardNo,
endCardNo=endCardNo, cardFace=cardFace)
# 出库 ---> 卡片类别获取
cardTypeRes = cSO.getCardType(cardHost=self.cardHost, webHeaders=self.webHeaders)
# 获取用户信息
userInfo = cSO.getUserInfo(cardHost=self.cardHost, webHeaders=self.webHeaders, name=self.applyUserCode,
keyword=self.applyUserCode)
assert userInfo.json()["data"][0]["id"] == self.applyUserId, "获取到的用户信息与实际用户信息不匹配"
# 出库 ---> 卡面信息获取
cardFaceB = cSI.returnFaceValue(resCardFace=cSO.getCardFace(cardHost=self.cardHost, webHeaders=self.webHeaders),
faceNum=faceNum)
# 出库 ---> 卡片入库卡面与当前卡面对比
for cardNo in range(startCardNo, endCardNo + 1):
cardState = cSO.checkCardForOut(cardHost=self.cardHost, webHeaders=self.webHeaders, cardFace=cardFaceB,
cardNo=cardNo)
assert cardState.json()["code"] == "200", "卡片面校验不通过"
assert cardFace == cardFaceB, "卡面信息断言失败"
# 出库 ---> 卡片出库
cardNos = str(startCardNo) + "," + str(endCardNo)
amount = len([i for i in range(startCardNo, endCardNo + 1)])
outCardRes = cSO.cardAddOut(cardHost=self.cardHost, webHeaders=self.webHeaders, cardNos=cardNos,
applyUserName=self.applyUserName, applyUserId=self.applyUserId,
applyUserCode=self.applyUserCode, amount=amount)
assert outCardRes.json()["code"] == "200", "出库失败"
# 根据领取人获取最新的出库记录
startDate = str(time.strftime("%Y-%m-%d 00:00:00", time.localtime()))
endDate = str(time.strftime("%Y-%m-%d 23:59:59", time.localtime()))
listRes = cSO.getOutPage(cardHost=self.cardHost, webHeaders=self.webHeaders,startDate=startDate,endDate=endDate)
pageNum = math.ceil(listRes.json()["total"]/10)
listRes = cSO.getOutPage(cardHost=self.cardHost, webHeaders=self.webHeaders, startDate=startDate,
endDate=endDate,page=pageNum)
dateList = [i["applyTime"] for i in listRes.json()["rows"]]
assert [] == [i for i in dateList if i < startDate or i > endDate], "查询结果错误,查询出非当天的入库信息"
def test_searchAllOption(self):
# 先添加入库卡片
faceNum = 3
startCardNo = int(time.strftime("%y%m%d%H%M%S", time.localtime()))
endCardNo = startCardNo + 1
cardFace = cSI.returnFaceValue(resCardFace=cSI.getCardFace(cardHost=self.cardHost, webHeaders=self.webHeaders),
faceNum=faceNum)
resSavaCard = cSI.savaCard(cardHost=self.cardHost, webHeaders=self.webHeaders, startCardNo=startCardNo,
endCardNo=endCardNo, cardFace=cardFace)
# 出库 ---> 卡片类别获取
cardTypeRes = cSO.getCardType(cardHost=self.cardHost, webHeaders=self.webHeaders)
# 获取用户信息
userInfo = cSO.getUserInfo(cardHost=self.cardHost, webHeaders=self.webHeaders, name=self.applyUserCode,
keyword=self.applyUserCode)
assert userInfo.json()["data"][0]["id"] == self.applyUserId, "获取到的用户信息与实际用户信息不匹配"
# 出库 ---> 卡面信息获取
cardFaceB = cSI.returnFaceValue(resCardFace=cSO.getCardFace(cardHost=self.cardHost, webHeaders=self.webHeaders),
faceNum=faceNum)
# 出库 ---> 卡片入库卡面与当前卡面对比
for cardNo in range(startCardNo, endCardNo + 1):
cardState = cSO.checkCardForOut(cardHost=self.cardHost, webHeaders=self.webHeaders, cardFace=cardFaceB,
cardNo=cardNo)
assert cardState.json()["code"] == "200", "卡片面校验不通过"
assert cardFace == cardFaceB, "卡面信息断言失败"
# 出库 ---> 卡片出库
cardNos = str(startCardNo) + "," + str(endCardNo)
amount = len([i for i in range(startCardNo, endCardNo + 1)])
outCardRes = cSO.cardAddOut(cardHost=self.cardHost, webHeaders=self.webHeaders, cardNos=cardNos,
applyUserName=self.applyUserName, applyUserId=self.applyUserId,
applyUserCode=self.applyUserCode, amount=amount)
assert outCardRes.json()["code"] == "200", "出库失败"
# 根据领取人获取最新的出库记录
startDate = str(time.strftime("%Y-%m-%d 00:00:00", time.localtime()))
endDate = str(time.strftime("%Y-%m-%d 23:59:59", time.localtime()))
# 根据领取人获取最新的出库记录
listRes = cSO.getOutPage(cardHost=self.cardHost, webHeaders=self.webHeaders, cardNo=startCardNo,startDate=startDate,endDate=endDate,applyUserName=self.applyUserName,
applyUserId=self.applyUserId)
assert 1 == len([i for i in listRes.json()["rows"]]), "查询结果不唯一,查询失败"
firstId = listRes.json()["rows"][0]["id"]
resDetail = cSO.getOutListDetail(cardHost=self.cardHost, webHeaders=self.webHeaders, id=firstId)
outCardDetail = re.findall("<ul><li>(.*?)</li></ul>", resDetail.text)
assert str(startCardNo) in outCardDetail, "查询失败"
def test_checkCardState(self):
# 先添加入库卡片
faceNum = 3
startCardNo = int(time.strftime("%y%m%d%H%M%S", time.localtime()))
endCardNo = startCardNo + 1
cardFace = cSI.returnFaceValue(resCardFace=cSI.getCardFace(cardHost=self.cardHost, webHeaders=self.webHeaders),
faceNum=faceNum)
resSavaCard = cSI.savaCard(cardHost=self.cardHost, webHeaders=self.webHeaders, startCardNo=startCardNo,
endCardNo=endCardNo, cardFace=cardFace)
# 出库 ---> 卡片类别获取
cardTypeRes = cSO.getCardType(cardHost=self.cardHost, webHeaders=self.webHeaders)
# 获取用户信息
userInfo = cSO.getUserInfo(cardHost=self.cardHost, webHeaders=self.webHeaders, name=self.applyUserCode,
keyword=self.applyUserCode)
assert userInfo.json()["data"][0]["id"] == self.applyUserId, "获取到的用户信息与实际用户信息不匹配"
# 出库 ---> 卡面信息获取
cardFaceB = cSI.returnFaceValue(resCardFace=cSO.getCardFace(cardHost=self.cardHost, webHeaders=self.webHeaders),
faceNum=faceNum)
# 出库 ---> 卡片入库卡面与当前卡面对比
for cardNo in range(startCardNo, endCardNo + 1):
cardState = cSO.checkCardForOut(cardHost=self.cardHost, webHeaders=self.webHeaders, cardFace=cardFaceB,
cardNo=cardNo)
assert cardState.json()["code"] == "200", "卡片面校验不通过"
assert cardFace == cardFaceB, "卡面信息断言失败"
# 出库 ---> 卡片出库
cardNos = str(startCardNo) + "," + str(endCardNo)
amount = len([i for i in range(startCardNo, endCardNo + 1)])
outCardRes = cSO.cardAddOut(cardHost=self.cardHost, webHeaders=self.webHeaders, cardNos=cardNos,
applyUserName=self.applyUserName, applyUserId=self.applyUserId,
applyUserCode=self.applyUserCode, amount=amount)
assert outCardRes.json()["code"] == "200", "出库失败"
# 已出库的卡在出库页面进行状态校验
for cardNo in range(startCardNo, endCardNo + 1):
cardState = cSO.checkCardForOut(cardHost=self.cardHost, webHeaders=self.webHeaders, cardFace=cardFaceB,
cardNo=cardNo)
assert cardState.json()["message"] == "该卡状态为[激活],不能进行此操作!", "提示信息错误"
assert cardState.json()["code"] == "5000", "出库失败"
# 未出库的卡校验
cardState = cSO.checkCardForOut(cardHost=self.cardHost, webHeaders=self.webHeaders, cardFace=cardFaceB,
cardNo=startCardNo+2)
assert cardState.json()["message"] == "该卡未入库!", "提示信息错误"
assert cardState.json()["code"] == "10000", "未出库的卡片状态校验失败"
# 已开卡的状态校验,暂缺