test_openMasterCard.py 18.4 KB
#coding=utf-8

# @Time    : 2021/5/26 10:16
# @Author  : Ljq
# @File    : test_openMasterCard.py
# @Software: PyCharm


"""
    主卡开卡测试
"""

import unittest
import requests
import time
import json
import math
import commons.api.cardStorageIn as cSI
import commons.api.returnCard as reC
import commons.api.cardStorageOut as cSO
import commons.api.openCard as oMC
import commons.api.cardStock as cS
from commons.scripts.createIdNum import cIN
from commons.api.doLogin import doLogin
from commons.readConf import readConfig

class tset_openMasterCard(unittest.TestCase):
    def setUp(self) -> None:
        pass

    def tearDown(self) -> None:
        pass

    @classmethod
    def setUpClass(cls) -> None:
        # 配置信息获取
        readC = readConfig()
        cls.cardHost = readC.returnOptionsItems("host", "cardHost")
        cls.gatewayHost = readC.returnOptionsItems("host", "gatewayHost")
        cls.cCNum = readC.returnOptionsItems("testInfo","cCNum")
        cls.cCNumB = readC.returnOptionsItems("testInfo", "cCNumB")
        cls.cardNum = readC.returnOptionsItems("testInfo", "cardNum")
        cls.cardNumRe = readC.returnOptionsItems("testInfo", "cardNumRe")
        cls.loginPwd = readC.returnOptionsItems("testInfo", "loginPwd")
        # 登录信息获取
        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"]
        cls.firmId = cls.userInfo["data"]["user"]["firmId"]

    @classmethod
    def tearDownClass(cls) -> None:
        pass

    def test_getCustomerInfo(self):
        """
        客户查询测试
        :return:
        """
        # 正确的获取客户信息
        res = oMC.getCustomerInfo(gatewayHost=self.gatewayHost,clientHeaders=self.clientHeaders,cCNum=self.cCNum)
        print(res.json())
        assert "200" == res.json()["code"],"使用已存在的客户信息查询失败"
        # 获取客户身份类型
        res = oMC.getSubTypeName(gatewayHost=self.gatewayHost,clientHeaders=self.clientHeaders,customerId=res.json()["data"]["id"])
        assert "200" == res.json()["code"],"查询客户身份类型失败"
        assert "" != res.json()["data"], "身份类型不应该为空"

        # 使用不存在的证件号进行查询
        res = oMC.getCustomerInfo(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders, cCNum=cIN())
        assert "20002" == res.json()["code"], "使用不存在的客户信息查询时查询结果不一致"

    def test_checkNewCardNo(self):
        """
        卡状态校验
        :return:
        """
        # 正向测试卡面校验功能---> #获取客户信息
        print(self.clientHeaders)
        resCusInfo = oMC.getCustomerInfo(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders, cCNum=self.cCNum)
        print(resCusInfo.json())
        assert "200" == resCusInfo.json()["code"], "使用已存在的客户信息查询失败"
        # 校验
        res = oMC.checkNewCardNo(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders, cardNo=self.cardNum,customerId=resCusInfo.json()["data"]["id"],customerType=resCusInfo.json()["data"]["customerType"])
        print("res.json()", res.json())
        assert "200" == res.json()["code"], "使用已存在未开卡的卡片进行校验校验失败"

        # 使用未入库的卡片进行校验
        res = oMC.checkNewCardNo(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders, cardNo=999999999999,
                                 customerId=resCusInfo.json()["data"]["id"],
                                 customerType=resCusInfo.json()["data"]["customerType"])
        assert "10000" == res.json()["code"], "使用已存在未开卡的卡片进行校验校验失败"
        assert "该卡未入库!" == res.json()["message"], "message信息与预期信息不匹配"

        # 未出库的卡片进行校验
        resCardFace = cSI.getCardFace(cardHost=self.cardHost, webHeaders=self.webHeaders)
        cardFace = cSI.returnFaceValue(resCardFace=resCardFace, faceNum=1)
        if self.firmId == 9:
            startCardNo, endCardNo = 999999999998, 999999999998
        elif self.firmId == 8:
            startCardNo, endCardNo = 999999999997, 999999999997
        resSavaCard = cSI.savaCard(cardHost=self.cardHost, webHeaders=self.webHeaders, startCardNo=startCardNo,
                                   endCardNo=endCardNo, cardFace=cardFace)
        res = oMC.checkNewCardNo(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders, cardNo=startCardNo,
                                 customerId=resCusInfo.json()["data"]["id"],
                                 customerType=resCusInfo.json()["data"]["customerType"])
        print(res.json())
        assert "20000" == res.json()["code"], "未出库的卡片进行校验校验失败"
        assert "该卡状态为[未激活],不能开卡!" == res.json()["message"], "未出库卡片校验,message信息与预期信息不匹配"

        # 对已开卡的卡片进行校验
        res = oMC.checkNewCardNo(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders, cardNo=self.cardNumRe,
                                 customerId=resCusInfo.json()["data"]["id"],
                                 customerType=resCusInfo.json()["data"]["customerType"])
        print(res.json())
        assert "20000" == res.json()["code"], "未出库的卡片进行校验校验失败"
        assert "该卡状态为[在用],不能开卡!" == res.json()["message"], "未出库卡片校验,message信息与预期信息不匹配"

    def test_getOpenCardFee(self):
        """收费项获取"""
        # 获取开卡手续费
        res = oMC.getOpenCardFee(gatewayHost=self.gatewayHost,clientHeaders=self.clientHeaders)
        print(res.json())
        assert "200" == res.json()["code"],"开卡手续费获取失败"
        assert "" != res.json()["data"],"开卡手续费获取失败"

    def test_openMasterCard(self):
        """
        正向开卡流程
        :return:
        """
        # 卡片出库
        faceNum = 1
        resCardFace = cSI.getCardFace(cardHost=self.cardHost, webHeaders=self.webHeaders)
        cardFace = cSI.returnFaceValue(resCardFace=resCardFace, faceNum=faceNum)
        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)
        # 出库
        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", "出库失败"


        # 获取手续费
        costFee = oMC.getOpenCardFee(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders).json()["data"]
        print(costFee)
        # 获取客户信息
        resCusInfo = oMC.getCustomerInfo(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders,
                                         cCNum=self.cCNum).json()["data"]
        print(resCusInfo)
        # 客户信息准备
        customerName = resCusInfo["name"]
        customerType = resCusInfo["customerType"]
        customerId = resCusInfo["id"]
        customerOrganizationType=resCusInfo["organizationType"]
        customerCredentialType = resCusInfo["certificateType"]
        customerContactsPhone = resCusInfo["customerContactsPhone"]
        customerCertificateNumber = resCusInfo["certificateNumber"]
        customerCode = resCusInfo["code"]
        name = self.applyUserName
        holdName = resCusInfo["name"]
        holdContactsPhone = resCusInfo["customerContactsPhone"]

        # 卡片状态校验
        resCheck = oMC.checkNewCardNo(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders, cardNo=startCardNo,
                                 customerId=customerId,
                                 customerType=customerType)
        print(resCheck.json())
        assert "200" == resCheck.json()["code"],"卡片校验失败"

        # 开卡
        print("开始开卡")
        resOpenCard = oMC.openMasterCard(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders, cardNo=startCardNo,
                                         costFee=costFee, customerName=customerName, customerType=customerType,
                                         customerId=customerId, loginPwd=self.loginPwd,
                                         customerOrganizationType=customerOrganizationType,
                                         customerCredentialType=customerCredentialType,
                                         customerContactsPhone=customerContactsPhone,
                                         customerCertificateNumber=customerCertificateNumber, customerCode=customerCode,
                                         name=name, holdName=holdName, holdContactsPhone=holdContactsPhone,cardType=10)

        print("resOpenCard.json()",resOpenCard.json())

        assert "200" == resOpenCard.json()["code"],"开卡失败"
        assert None != resOpenCard.json()["data"], "开卡失败"

        # 获取卡信息
        reC.returnCardDef(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders, cardNo=startCardNo)

    def test_dupOpenCard(self):
        """
        不能重复开卡
        :return:
        """
        # 卡片出库
        faceNum = 1
        resCardFace = cSI.getCardFace(cardHost=self.cardHost, webHeaders=self.webHeaders)
        cardFace = cSI.returnFaceValue(resCardFace=resCardFace, faceNum=faceNum)
        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)
        # 出库
        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", "出库失败"

        # 获取手续费
        costFee = oMC.getOpenCardFee(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders).json()["data"]
        print(costFee)
        # 获取客户信息
        resCusInfo = oMC.getCustomerInfo(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders,
                                         cCNum=self.cCNum).json()["data"]
        print(resCusInfo)
        # 客户信息准备
        customerName = resCusInfo["name"]
        customerType = resCusInfo["customerType"]
        customerId = resCusInfo["id"]
        customerOrganizationType = resCusInfo["organizationType"]
        customerCredentialType = resCusInfo["certificateType"]
        customerContactsPhone = resCusInfo["customerContactsPhone"]
        customerCertificateNumber = resCusInfo["certificateNumber"]
        customerCode = resCusInfo["code"]
        name = self.applyUserName
        holdName = resCusInfo["name"]
        holdContactsPhone = resCusInfo["customerContactsPhone"]

        # 卡片状态校验
        resCheck = oMC.checkNewCardNo(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders,
                                      cardNo=startCardNo,
                                      customerId=customerId,
                                      customerType=customerType)
        print(resCheck.json())
        assert "200" == resCheck.json()["code"], "卡片校验失败"

        # 开卡
        print("开始开卡")
        resOpenCard = oMC.openMasterCard(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders,
                                         cardNo=startCardNo,
                                         costFee=costFee, customerName=customerName, customerType=customerType,
                                         customerId=customerId, loginPwd=self.loginPwd,
                                         customerOrganizationType=customerOrganizationType,
                                         customerCredentialType=customerCredentialType,
                                         customerContactsPhone=customerContactsPhone,
                                         customerCertificateNumber=customerCertificateNumber, customerCode=customerCode,
                                         name=name, holdName=holdName, holdContactsPhone=holdContactsPhone, cardType=10)
        print("resOpenCard.json()", resOpenCard.json())
        assert "200" == resOpenCard.json()["code"], "开卡失败"
        assert None != resOpenCard.json()["data"], "开卡失败"

        resOpenCard = oMC.openMasterCard(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders,
                                         cardNo=startCardNo,
                                         costFee=costFee, customerName=customerName, customerType=customerType,
                                         customerId=customerId, loginPwd=self.loginPwd,
                                         customerOrganizationType=customerOrganizationType,
                                         customerCredentialType=customerCredentialType,
                                         customerContactsPhone=customerContactsPhone,
                                         customerCertificateNumber=customerCertificateNumber, customerCode=customerCode,
                                         name=name, holdName=holdName, holdContactsPhone=holdContactsPhone, cardType=10)
        print("resOpenCard.json()", resOpenCard.json())
        assert "20000" == resOpenCard.json()["code"], "重复开卡失败测试不通过"
        assert "该卡状态为[在用],不能开卡!" == resOpenCard.json()["message"], "重复开卡失败测试不通过"

        # 获取卡信息
        reC.returnCardDef(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders, cardNo=startCardNo)

    def test_oneCardOneCus(self):
        """
        一张卡只能同时开被开卡给一个用户
        :return:
        """
        # 卡片入库
        faceNum = 1
        startCardNo = int(time.strftime("%y%m%d%H%M%S", time.localtime()))
        endCardNo = startCardNo+1

        resCardFace = cSI.getCardFace(cardHost=self.cardHost, webHeaders=self.webHeaders)
        cardFace = cSI.returnFaceValue(resCardFace=resCardFace, faceNum=faceNum)
        resSavaCard = cSI.savaCard(cardHost=self.cardHost, webHeaders=self.webHeaders, startCardNo=startCardNo,
                                   endCardNo=endCardNo, cardFace=cardFace)
        # 出库
        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", "出库失败"

        # 开卡给第一个客户
        resFirstOpen = oMC.openMasterCardDef(gatewayHost=self.gatewayHost,clientHeaders=self.clientHeaders,cCNum=self.cCNum,cardNo=startCardNo,applyUserName=self.applyUserName)
        assert "200" == resFirstOpen.json()["code"],"第一次开卡,开卡失败"
        assert "data" in resFirstOpen.json(), "第一次开卡,开卡失败"

        # 开卡给第二个客户
        resSecondOpen = oMC.openMasterCardDef(gatewayHost=self.gatewayHost,clientHeaders=self.clientHeaders,cCNum=self.cCNumB,cardNo=startCardNo,applyUserName=self.applyUserName)
        print("resSecondOpen.json()   - - ->",resSecondOpen.json())
        assert "20000" == resSecondOpen.json()["code"], "一张卡不能开卡给多用户测试不通过"
        assert "该卡状态为[在用],不能开卡!" in resSecondOpen.text, "一张卡不能开卡给多用户测试不通过"

        # 退卡
        reC.returnCardDef(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders, cardNo=startCardNo)

    def test_openCardState(self):
        """
        不同异常状态的卡片在入库时的开卡情况
        :return:
        """
        # 卡片入库
        faceNum = 1
        startCardNo = int(time.strftime("%y%m%d%H%M%S", time.localtime()))
        endCardNo = startCardNo+1

        resCardFace = cSI.getCardFace(cardHost=self.cardHost, webHeaders=self.webHeaders)
        cardFace = cSI.returnFaceValue(resCardFace=resCardFace, faceNum=faceNum)
        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", "新出库卡片作废测试失败"
        resFirstOpen = oMC.openMasterCardDef(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders,
                                             cCNum=self.cCNum, cardNo=startCardNo, applyUserName=self.applyUserName)
        print(resFirstOpen.json())
        assert "20000" == resFirstOpen.json()["code"], "已作废的卡片不能开卡,测试不通过"
        assert "该卡状态为[作废],不能开卡!" == resFirstOpen.json()["message"], "已作废的卡片不能开卡,提示信息错误"

        # 未出库的卡片出库失败
        resFirstOpen = oMC.openMasterCardDef(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders,
                                             cCNum=self.cCNum, cardNo=endCardNo, applyUserName=self.applyUserName)
        print(resFirstOpen.json())
        assert "20000" == resFirstOpen.json()["code"], "未激活的卡片不能开卡,测试不通过"
        assert "该卡状态为[未激活],不能开卡!" == resFirstOpen.json()["message"], "未激活的卡片不能开卡,提示信息错误"