test_outCard.py 17.6 KB
#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", "未出库的卡片状态校验失败"

        # 已开卡的状态校验,暂缺