test_addCard.py
11.4 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
# -*- coding: utf-8 -*-
# @Time : 2021/7/16 14:44
# @Author : Ljq
# @File : test_addCard.py
# @Software: PyCharm
"""
卡片入库测试
"""
import unittest
import requests
import time
import json
import math
import commons.api.cardStorageIn as cSI
import commons.api.cardStock as cS
import commons.api.cardStorageOut as cSO
from commons.readConf import readConfig
from commons.api.doLogin import doLogin
from commons.MySession import mysession
class test_addCard(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"]
# print("self.webHeaders", cls.webHeaders)
# print("self.clientHeaders", cls.clientHeaders)
# print("self.userInfo", cls.userInfo)
def setUp(self) -> None:
time.sleep(2)
def test_cardType(self):
"""
卡类型校验
:return:
"""
resCardType = cSI.getCardType(cardHost=self.cardHost, webHeaders=self.webHeaders)
preRes = [{"text":"-- 全部 --","value":""},{"text":"主卡","value":10},{"text":"副卡","value":20}]
assert resCardType.json()==preRes,"卡类型信息错误"
def test_cardFaceCheck(self):
"""
市场卡面信息校验
:return:
"""
resCardFace = cSI.getCardFace(cardHost=self.cardHost,webHeaders=self.webHeaders)
print(resCardFace.json())
if self.userInfo["data"]["user"]["firmId"] == 8:
# 预期结果定义
preRes = [{'text': '-- 请选择 --', 'value': ''}, {'text': '买方卡', 'value': 'buyer'}, {'text': 'VIP买方卡', 'value': 'buyer_vip'}, {'text': '卖方卡', 'value': 'seller'}, {'text': '司机卡', 'value': 'driver'}]
assert resCardFace.json()==preRes,"当 firmId = 8 时卡面信息错误"
else:
preRes = [{"text":"-- 无--","value":""}]
assert resCardFace.json() == preRes, "当 firmId != 8 时卡面信息错误"
def test_doCardStorageIn(self):
"""
卡片入库测试,新添加的卡片能正常的入库
:return:
"""
# 获取卡面信息
resCardFace = cSI.getCardFace(cardHost=self.cardHost,webHeaders=self.webHeaders)
cardFace = cSI.returnFaceValue(resCardFace=resCardFace,faceNum=3)
startCardNo = int(time.strftime("%y%m%d%H%M%S", time.localtime()))
endCardNo = startCardNo + 1
# 执行入库
resSavaCard = cSI.savaCard(cardHost=self.cardHost,webHeaders=self.webHeaders,startCardNo=startCardNo,endCardNo=endCardNo,cardFace=cardFace)
# print(resSavaCard.json())
assert resSavaCard.json()["message"]=="OK","入库失败"
resQueryList = cSI.queryList(cardHost=self.cardHost,webHeaders=self.webHeaders)
# 入库卡片号段校验
assert resQueryList.json()["rows"][0]["cardNoRange"]==str(startCardNo)+"-"+str(endCardNo),"入库的卡片在入库列表不能被查询到"
# 入库数量校验
assert resQueryList.json()["rows"][0]["amount"]==2,"入库数量错误"
# 入库角色校验
assert resQueryList.json()["rows"][0]["creator"]==self.userInfo["data"]["user"]["realName"],"入库角色记录正确"
assert resQueryList.json()["rows"][0]["creatorId"] == self.userInfo["data"]["user"]["id"], "入库角色记录正确"
# resQueryList.json()["rows"][0]["cardFaceText"]
if self.userInfo["data"]["user"]["firmId"] == 8:
assert cardFace==resQueryList.json()["rows"][0]["cardFace"],"记录的卡面信息与实际卡面不一致"
else:
assert "cardFaceText" not in resQueryList.text,"记录的卡面信息与实际卡面不一致"
def test_duplicateStorageIn(self):
"""
测试卡片不能被重复入库
:return:
"""
resCardFace = cSI.getCardFace(cardHost=self.cardHost,webHeaders=self.webHeaders)
cardFace = cSI.returnFaceValue(resCardFace=resCardFace,faceNum=3)
startCardNo = int(time.strftime("%y%m%d%H%M%S", time.localtime()))
endCardNo = startCardNo+1
resSavaCard = cSI.savaCard(cardHost=self.cardHost,webHeaders=self.webHeaders,startCardNo=startCardNo,endCardNo=endCardNo,cardFace=cardFace)
assert resSavaCard.json()["message"]=="OK","入库失败"
resSavaCard = cSI.savaCard(cardHost=self.cardHost,webHeaders=self.webHeaders,startCardNo=startCardNo,endCardNo=endCardNo,cardFace=cardFace)
assert resSavaCard.json()["message"]=="入库失败,包含重复卡号%s~%s"%(startCardNo,endCardNo),"卡片不能重复入库验证失败"
def test_openCardStorageIn(self):
"""
入库列表查询测试
:return:
"""
# 全列表查询
resQueryList = cSI.queryList(cardHost=self.cardHost, webHeaders=self.webHeaders)
# print(resQueryList.json()["total"])
assert resQueryList.json()["total"]>200,"页数小于10,查询结果可能存在错误"
# 查询当天入库的入库记录,判断所得的查询记录的日期都是当天的为测试通过
startDate = str(time.strftime("%Y-%m-%d 00:00:00", time.localtime()))
endDate = str(time.strftime("%Y-%m-%d 23:59:59", time.localtime()))
resQueryLista = cSI.queryList(cardHost=self.cardHost,webHeaders=self.webHeaders,startDate=startDate,endDate=endDate)
dateList=[]
pageNums = math.ceil(resQueryLista.json()["total"]/10)
for pageNum in range(pageNums):
resQueryLista = cSI.queryList(cardHost=self.cardHost, webHeaders=self.webHeaders, startDate=startDate,
endDate=endDate,page=str(pageNum+1))
dateList = dateList+[i["createTime"] for i in resQueryLista.json()["rows"]]
assert [] == [i for i in dateList if i<startDate or i>endDate],"查询结果错误,查询出非当天的入库信息"
def test_addMasterCard(self):
"""
添加主卡
:return:
"""
resCardType = cSI.getCardType(cardHost=self.cardHost,webHeaders=self.webHeaders)
resCardFace = cSI.getCardFace(cardHost=self.cardHost,webHeaders=self.webHeaders)
cardFace = cSI.returnFaceValue(resCardFace=resCardFace,faceNum=3)
startCardNo = int(time.strftime("%y%m%d%H%M%S", time.localtime()))
endCardNo = startCardNo+1
resSavaCard = cSI.savaCard(cardHost=self.cardHost,webHeaders=self.webHeaders,startCardNo=startCardNo,endCardNo=endCardNo,cardFace=cardFace)
resQueryList = cSI.queryList(cardHost=self.cardHost, webHeaders=self.webHeaders)
assert resQueryList.json()["rows"][0]["cardType"]==10,"卡片类型错误"
def test_addSlaveCard(self):
"""
添加副卡
:return:
"""
resCardType = cSI.getCardType(cardHost=self.cardHost,webHeaders=self.webHeaders)
startCardNo = int(time.strftime("%y%m%d%H%M%S", time.localtime()))
endCardNo = startCardNo+1
resSavaCard = cSI.savaCard(cardHost=self.cardHost,webHeaders=self.webHeaders,startCardNo=startCardNo,endCardNo=endCardNo,cardType=20)
print(resSavaCard.json())
resQueryList = cSI.queryList(cardHost=self.cardHost, webHeaders=self.webHeaders)
assert resQueryList.json()["rows"][0]["cardType"] == 20, "卡片类型错误"
assert resQueryList.json()["rows"][0]["cardTypeText"] == "副卡", "卡片类型错误"
assert "cardFaceText" not in str(resQueryList.json()["rows"][0]),"副卡不应该存在卡面"
def test_delStorageInRecord(self):
"""
正常删除卡片记录
:return:
"""
# 新增加一条入库记录用于删除
resCardFace = cSI.getCardFace(cardHost=self.cardHost,webHeaders=self.webHeaders)
cardFace = cSI.returnFaceValue(resCardFace=resCardFace,faceNum=3)
startCardNo = int(time.strftime("%y%m%d%H%M%S", time.localtime()))
endCardNo = startCardNo + 1
resSavaCard = cSI.savaCard(cardHost=self.cardHost,webHeaders=self.webHeaders,startCardNo=startCardNo,endCardNo=endCardNo,cardFace=cardFace)
assert resSavaCard.json()["message"]=="OK","入库失败"
resQueryList = cSI.queryList(cardHost=self.cardHost, webHeaders=self.webHeaders)
ida = resQueryList.json()['rows'][0]['id']
resDel = cSI.delCard(cardHost=self.cardHost,webHeaders=self.webHeaders,ids=ida)
assert resDel.json()["message"]=="OK","删除失败,入库记录未被成功删除"
resQueryListB = cSI.queryList(cardHost=self.cardHost, webHeaders=self.webHeaders)
idb = resQueryListB.json()['rows'][0]['id']
print(ida,"----------------",idb)
assert ida!=idb,"删除功能异常,记录未被删除"
def test_delStorageInRecordFail_delCard(self):
"""
已作废的卡片不能被删除
:return:
"""
resCardFace = cSI.getCardFace(cardHost=self.cardHost,webHeaders=self.webHeaders)
cardFace = cSI.returnFaceValue(resCardFace=resCardFace,faceNum=3)
startCardNo = int(time.strftime("%y%m%d%H%M%S", time.localtime()))
endCardNo = startCardNo+1
resSavaCard = cSI.savaCard(cardHost=self.cardHost,webHeaders=self.webHeaders,startCardNo=startCardNo,endCardNo=endCardNo,cardFace=cardFace)
# 卡片作废
cS.cardVoid(cardHost=self.cardHost,webHeaders=self.webHeaders,cardNo=startCardNo)
# 删除入库记录
resQueryList = cSI.queryList(cardHost=self.cardHost, webHeaders=self.webHeaders)
ida = resQueryList.json()['rows'][0]['id']
resDel = cSI.delCard(cardHost=self.cardHost, webHeaders=self.webHeaders, ids=ida)
print(resDel.json())
assert resDel.json()["message"]=="有部分卡片已出库或作废,删除失败","已作废的卡片不能被删除"
def test_delStorageInRecordFail_cardOut(self):
"""
存在出库卡片的入库记录,不能进行删除
:return:
"""
resCardFace = cSI.getCardFace(cardHost=self.cardHost, webHeaders=self.webHeaders)
cardFace = cSI.returnFaceValue(resCardFace=resCardFace, faceNum=3)
startCardNo = int(time.strftime("%y%m%d%H%M%S", time.localtime()))
endCardNo = startCardNo + 1
resSavaCard = cSI.savaCard(cardHost=self.cardHost, webHeaders=self.webHeaders, startCardNo=startCardNo,
endCardNo=endCardNo, cardFace=cardFace)
# 卡片出库
acc = cSO.cardAddOut(cardHost=self.cardHost, webHeaders=self.webHeaders, cardNos=str(startCardNo),applyUserName=self.applyUserName,applyUserCode=self.applyUserCode,applyUserId=self.applyUserId)
# print(acc.json())
# 删除入库记录
resQueryList = cSI.queryList(cardHost=self.cardHost, webHeaders=self.webHeaders)
ida = resQueryList.json()['rows'][0]['id']
resDel = cSI.delCard(cardHost=self.cardHost, webHeaders=self.webHeaders, ids=ida)
# print(resDel.json())
assert resDel.json()["message"] == "有部分卡片已出库或作废,删除失败", "已出库的卡片不能被删除"
@classmethod
def tearDownClass(cls):
print("tearDown")
def tearDown(self) -> None:
pass
if __name__== "__main__":
unittest.main()