test_cardStorage.py 7.84 KB
#coding=utf-8

# @Time    : 2021/5/24 15:41
# @Author  : Ljq
# @File    : test_cardStorage.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

class test_cardStorage(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_queryCardStorageList(self):
        """
        库存列表测试
        :return:
        """
        resQuery = cS.queryCardStorageList(cardHost=self.cardHost,webHeaders=self.webHeaders)
        print(resQuery.json())
        assert "200" == resQuery.json()["code"],"查询失败"
        # 列表翻页
        pageNum = math.ceil(resQuery.json()["total"]/10)
        print(pageNum)
        for num in range(pageNum):
            resQuery = cS.queryCardStorageList(cardHost=self.cardHost, webHeaders=self.webHeaders,page=num+1)
            assert "200" == resQuery.json()["code"], "查询失败"
            if num >5:
                break
            elif num>0:
                sTime = resQuery.json()["rows"][0]["createTime"]
                # print(str(num)+"        sTime       "+sTime)
                # print(str(num) + "        eTime       " + eTime)
                assert sTime <= eTime,"当前页第一列数据的创建时间应该小于上一页的最后一条数据的结束时间"
            eTime = resQuery.json()["rows"][9]["createTime"]

    def test_cardVoid(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)
        # 新入库卡片作废
        resVoid = cS.cardVoid(cardHost=self.cardHost,webHeaders=self.webHeaders,cardNo=startCardNo)
        print(resVoid.json())
        assert resVoid.json()["code"]=="200","新入库卡片作废测试失败"

        # 新出库的卡片可以作废
        cardNos = str(endCardNo)
        amount = 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", "出库失败"
        resVoid = cS.cardVoid(cardHost=self.cardHost, webHeaders=self.webHeaders, cardNo=cardNos)
        print(resVoid.json())
        assert resVoid.json()["code"] == "200", "新出库卡片作废测试失败"

        # 已开卡的卡片不能进行作废

    def test_searchAllOptions(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+6
        resSavaCard = cSI.savaCard(cardHost=self.cardHost,webHeaders=self.webHeaders,startCardNo=startCardNo,endCardNo=endCardNo,cardFace=cardFace)

        # 新入库卡片作废
        resVoid = cS.cardVoid(cardHost=self.cardHost,webHeaders=self.webHeaders,cardNo=startCardNo)
        print(resVoid.json())
        assert resVoid.json()["code"]=="200","新入库卡片作废测试失败"
        # 卡片库存作废状态查询
        resQuery = cS.queryCardStorageList(cardHost=self.cardHost, webHeaders=self.webHeaders,cardNo=startCardNo)
        assert "200" == resQuery.json()["code"], "查询失败"
        assert "3" == str(resQuery.json()["rows"][0]["state"]),"状态查询成功"
        # 卡片库存激活状态查询
        outCardRes = cSO.cardAddOut(cardHost=self.cardHost, webHeaders=self.webHeaders, cardNos=startCardNo+1,
                                    applyUserName=self.applyUserName, applyUserId=self.applyUserId,
                                    applyUserCode=self.applyUserCode, amount=1)
        resQuery = cS.queryCardStorageList(cardHost=self.cardHost, webHeaders=self.webHeaders, cardNo=startCardNo+1)
        assert "200" == resQuery.json()["code"], "查询失败"
        assert "2" == str(resQuery.json()["rows"][0]["state"]), "状态查询成功"

        # 查询主卡
        resQuery = cS.queryCardStorageList(cardHost=self.cardHost, webHeaders=self.webHeaders, type=10)
        assert "200" == resQuery.json()["code"], "查询失败"
        assert 10 == list(set([i["type"] for i in resQuery.json()["rows"]]))[0], "查库存中的主卡失败"
        # 查询副卡
        resQuery = cS.queryCardStorageList(cardHost=self.cardHost, webHeaders=self.webHeaders, type=20)
        assert "200" == resQuery.json()["code"], "查询失败"
        assert 20 == list(set([i["type"] for i in resQuery.json()["rows"]]))[0], "查库存中的副卡失败"

        # 查询卡面
        resCardFace = cSI.getCardFace(cardHost=self.cardHost,webHeaders=self.webHeaders)
        if len(resCardFace.json())>1:
            cardFaceList = [i["value"] for i in resCardFace.json()][1:]
            print(cardFaceList)
            for cardFaceItem in cardFaceList:
                print("1----------------------")
                resQuery = cS.queryCardStorageList(cardHost=self.cardHost, webHeaders=self.webHeaders,
                                                   cardFace=cardFaceItem)
                assert 1 == len(list(set([i["cardFace"] for i in resQuery.json()["rows"]]))), "失败"
                assert cardFaceItem == list(set([i["cardFace"] for i in resQuery.json()["rows"]]))[0], "卡面查询校验失败"
        else:
            print("2----------------------")
            resQuery = cS.queryCardStorageList(cardHost=self.cardHost, webHeaders=self.webHeaders)
            assert "cardFace" not in resQuery.text, "卡面查询校验失败"

        # 卡号
        resQuery = cS.queryCardStorageList(cardHost=self.cardHost, webHeaders=self.webHeaders, cardNo=startCardNo)
        # print(len(resQuery.json()["rows"]))
        assert 1 == len(resQuery.json()["rows"]),"卡号查询失败"
        assert str(startCardNo) == resQuery.json()["rows"][0]["cardNo"], "卡号查询失败"

        # 入库时间查询
        startDate = str(time.strftime("%Y-%m-%d 00:00:00", time.localtime()))
        endDate = str(time.strftime("%Y-%m-%d 23:59:59", time.localtime()))
        resQuery = cS.queryCardStorageList(cardHost=self.cardHost, webHeaders=self.webHeaders,startDate=startDate,endDate=endDate)
        pageNums = math.ceil(resQuery.json()["total"]/10)
        dateList = []
        for pageNum in range(pageNums):
            resQuery = cS.queryCardStorageList(cardHost=self.cardHost, webHeaders=self.webHeaders,startDate=startDate,endDate=endDate,page=pageNum)
            dateList = dateList+[i["createTime"] for i in resQuery.json()["rows"]]
        assert [] == [i for i in dateList if i<startDate or i>endDate],"查询结果错误,查询出非当天的入库信息"