test_openSlaveCard.py 24.1 KB
#coding=utf-8

# @Time    : 2021/5/26 10:19
# @Author  : Ljq
# @File    : test_openSlaveCard.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.cardLostAndUnLost as cLAUL
import commons.api.cardStock as cS
from commons.readConf import readConfig
from commons.api.doLogin import doLogin

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_getAccountInfo(self):
        """
        获取卡片信息测试
        :return:
        """
        # 使用未入库的卡片进行获取
        resGet = oMC.getAccountInfo(gatewayHost=self.gatewayHost,clientHeaders =self.clientHeaders,cardNo=999999999999)
        print(resGet.json())
        assert "10001" == resGet.json()["code"],"未入库卡片信息获取测试不通过"
        assert "卡账户不存在" == resGet.json()["message"],"未入库卡片信息获取测试不通过"

        # 使用入库未出库的卡片进行信息获取
        # 卡片入库
        faceNum = 1
        startCardNo = int(time.strftime("%y%m%d%H%M%S", time.localtime()))
        endCardNo = startCardNo + 2

        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)
        resGet = oMC.getAccountInfo(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders, cardNo=startCardNo)
        print(resGet.json())
        assert "10001" == resGet.json()["code"], "未出库卡片信息获取测试不通过"
        assert "卡账户不存在" == resGet.json()["message"], "未出库卡片信息获取测试不通过"

        # 使用出库未开卡的卡片进行信息获取
        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", "出库失败"
        resGet = oMC.getAccountInfo(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders, cardNo=startCardNo)
        print(resGet.json())
        assert "10001" == resGet.json()["code"], "未出库卡片信息获取测试不通过"
        assert "卡账户不存在" == resGet.json()["message"], "未出库卡片信息获取测试不通过"

        # 使用已开卡的卡片可以正确的获取到客户信息
        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(), "开卡失败"
        resGet = oMC.getAccountInfo(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders, cardNo=startCardNo)
        # print("resGet.json()",resGet.json())
        assert "200" == resGet.json()["code"], "未出库卡片信息获取测试不通过"
        assert "data" in resGet.json(), "未出库卡片信息获取测试不通过"

        # 使用已挂失的卡片信息进行卡片信息获取
        accountId,customerId = resGet.json()["data"]["accountId"],resGet.json()["data"]["customerId"]
        resLossCard = cLAUL.lossCard(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders, cardNo=str(startCardNo),
                                     accountId=accountId, customerId=customerId, loginPwd=self.loginPwd)
        # print("resLossCard.json()",resLossCard.json())
        assert "200" == resLossCard.json()["code"],"已挂失的卡片获取卡片信息测试不通过"
        resGet = oMC.getAccountInfo(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders, cardNo=startCardNo)
        # print("resGet.json()", resGet.json())
        assert "2000" == resGet.json()["code"], "未出库卡片信息获取测试不通过"
        assert "该卡为挂失状态,不能进行此操作" == resGet.json()["message"], "未出库卡片信息获取测试不通过"
        # 解挂
        resUnLoss = cLAUL.unLostCard(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders, cardNo=str(startCardNo),
                                     accountId=accountId, customerId=customerId, loginPwd=self.loginPwd)
        # print("resUnLoss.json()",resUnLoss.json())

        # 账号冻结状态

        # 卡片锁定状态

        # 使用已退还的卡片进行卡片信息获取
        reC.returnCardDef(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders, cardNo=startCardNo)
        resGet = oMC.getAccountInfo(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders, cardNo=startCardNo)
        # print("resGet.json()", resGet.json())
        assert "2000" == resGet.json()["code"], "未出库卡片信息获取测试不通过"
        assert "该卡为退还状态,不能进行此操作" == resGet.json()["message"], "未出库卡片信息获取测试不通过"

    def test_checkSlaveCardNo(self):
        """测试副卡校验功能开卡"""
        # 使用未入库的副卡进行校验
        res = oMC.checkNewCardNo(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders, cardNo=999999999999,cardType=20)
        print(res.json())
        assert "10000" == res.json()["code"], "使用已存在未开卡的卡片进行校验校验失败"
        assert "该卡未入库!" == res.json()["message"], "message信息与预期信息不匹配"

        # 使用未出库的卡片进行校验
        startSlaveCardNo = int(time.strftime("%y%m%d%H%M%S", time.localtime()))
        endSlaveCardNo = startSlaveCardNo + 1
        resSavaCard = cSI.savaCard(cardHost=self.cardHost, webHeaders=self.webHeaders, startCardNo=startSlaveCardNo,
                                   endCardNo=endSlaveCardNo, cardType=20)
        res = oMC.checkNewCardNo(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders, cardNo=startSlaveCardNo,
                                 cardType=20)
        print(res.json())
        assert "20000" == res.json()["code"], "使用已存在未出库的卡片进行校验校验失败"
        assert "该卡状态为[未激活],不能开卡!" == res.json()["message"], "message信息与预期信息不匹配"

        # 使用已出库的卡片进行校验
        SlaveCardNos = str(startSlaveCardNo) + "," + str(endSlaveCardNo)
        amount = len([i for i in range(startSlaveCardNo, endSlaveCardNo + 1)])
        outCardRes = cSO.cardAddOut(cardHost=self.cardHost, webHeaders=self.webHeaders, cardNos=SlaveCardNos,
                                    applyUserName=self.applyUserName, applyUserId=self.applyUserId,
                                    applyUserCode=self.applyUserCode, amount=amount)
        assert outCardRes.json()["code"] == "200", "出库失败"
        res = oMC.checkNewCardNo(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders, cardNo=startSlaveCardNo,
                                 cardType=20)
        print(res.json())
        assert "200" == res.json()["code"], "使用已出库的卡片进行校验校验失败"
        assert "OK" == res.json()["message"], "message信息与预期信息不匹配"

        # 使用已作废的卡片进行校验
        resCardVoid = cS.cardVoid(cardHost=self.cardHost,webHeaders=self.webHeaders,cardNo=endSlaveCardNo)
        assert "200"==resCardVoid.json()["code"],"卡片作废失败"
        res = oMC.checkNewCardNo(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders,
                                 cardNo=endSlaveCardNo,
                                 cardType=20)
        assert "20000" == res.json()["code"], "使用已作废的卡片进行校验校验失败"
        assert "该卡状态为[作废],不能开卡!" == res.json()["message"], "message信息与预期信息不匹配"


        # 使用已开卡的卡片进行校验
        time.sleep(2)
        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)
        print("resSavaCard.json()  ->",resSavaCard.json())
        # 出库
        cardNos = str(startCardNo) + "," + str(endCardNo)
        print(cardNos)
        amount = len([i for i in range(startCardNo, endCardNo)])
        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)
        print("resFirstOpen",resFirstOpen.json())
        assert "200" == resFirstOpen.json()["code"], "第一次开卡,开卡失败"
        assert "data" in resFirstOpen.json(), "第一次开卡,开卡失败"
        # 副卡开卡
        resOpenSlaveCard = oMC.openSlaveCardDef(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders,
                                                cardNo=startCardNo, slaveCardNo=startSlaveCardNo,
                                                loginPwd=self.loginPwd, applyUserName=self.applyUserName,
                                                parentLoginPwd=self.loginPwd)
        print("resOpenSlaveCard     --->        ",resOpenSlaveCard.json())
        resCheckNewCardNo= oMC.checkNewCardNo(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders, cardNo=startSlaveCardNo,
                                 cardType=20)
        print(resCheckNewCardNo.json())
        assert "20000" == resCheckNewCardNo.json()["code"], "使用已开卡的卡片进行校验校验失败"
        assert "该卡状态为[在用],不能开卡!" == resCheckNewCardNo.json()["message"], "message信息与预期信息不匹配"
        # 副卡退卡
        reC.returnCardDef(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders, cardNo=startSlaveCardNo)


        # 使用已退卡的卡片进行校验
        resCheckNewCardNo = oMC.checkNewCardNo(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders,
                                               cardNo=startSlaveCardNo,
                                               cardType=20)
        print("203 resCheckNewCardNo ",resCheckNewCardNo.json())
        assert "200" == resCheckNewCardNo.json()["code"], "使用已开卡的卡片进行校验校验失败"
        assert "OK" == resCheckNewCardNo.json()["message"], "message信息与预期信息不匹配"
        # 主卡退卡
        reC.returnCardDef(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders, cardNo=startCardNo)


    def test_openSlaveCard(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)
        print("resSavaCard.json()  ->", resSavaCard.json())
        # 出库
        cardNos = str(startCardNo) + "," + str(endCardNo)
        print(cardNos)
        amount = len([i for i in range(startCardNo, endCardNo)])
        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)
        print("resFirstOpen", resFirstOpen.json())
        assert "200" == resFirstOpen.json()["code"], "第一次开卡,开卡失败"
        assert "data" in resFirstOpen.json(), "第一次开卡,开卡失败"

        # 副卡入库-出库-开卡
        startSlaveCardNo = int(time.strftime("%y%m%d%H%M%S", time.localtime()))
        endSlaveCardNo = startSlaveCardNo + 1
        resSavaCard = cSI.savaCard(cardHost=self.cardHost, webHeaders=self.webHeaders, startCardNo=startSlaveCardNo,
                                   endCardNo=endSlaveCardNo, cardType=20)
        res = oMC.checkNewCardNo(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders,
                                 cardNo=startSlaveCardNo,
                                 cardType=20)
        print(res.json())
        assert "20000" == res.json()["code"], "使用已存在未出库的卡片进行校验校验失败"
        assert "该卡状态为[未激活],不能开卡!" == res.json()["message"], "message信息与预期信息不匹配"
        slaveCardNos = str(startSlaveCardNo) + "," + str(endSlaveCardNo)
        amount = len([i for i in range(startSlaveCardNo, endSlaveCardNo + 1)])
        outCardRes = cSO.cardAddOut(cardHost=self.cardHost, webHeaders=self.webHeaders, cardNos=slaveCardNos,
                                    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)
        resGet = oMC.getAccountInfo(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders, cardNo=startCardNo).json()["data"]
        print("resGet    --->   ", resGet)
        customerName = resGet["customerName"]
        customerId = resGet["customerId"]
        customerCredentialType = resGet["customerCertificateType"]
        customerContactsPhone = resGet["customerContactsPhone"]
        loginPwd = self.loginPwd
        cardNo = startSlaveCardNo
        customerCertificateNumber = resGet["customerCertificateNumber"]
        cardType = 20
        customerCode = resGet["customerCode"]
        name = self.applyUserName
        parentAccountId = resGet["accountId"]
        parentLoginPwd = self.loginPwd
        holdName = customerName
        holdContactsPhone = customerContactsPhone
        resOpenSlaveCard = oMC.openSlaveCard(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders,
                                             customerName=customerName,
                                             customerId=customerId, customerContactsPhone=customerContactsPhone,
                                             loginPwd=loginPwd, cardNo=cardNo,
                                             customerCertificateNumber=customerCertificateNumber, cardType=cardType,
                                             costFee=costFee, customerCode=customerCode,
                                             name=name, parentAccountId=parentAccountId, parentLoginPwd=parentLoginPwd,
                                             holdName=holdName,
                                             holdContactsPhone=holdContactsPhone,
                                             customerCredentialType=customerCredentialType
                                             )

        # # 办理副卡方法封装
        # resOpenSlaveCard = oMC.openSlaveCardDef(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders,
        #                                         cardNo=startCardNo, slaveCardNo=startSlaveCardNo,
        #                                         loginPwd=self.loginPwd, applyUserName=self.applyUserName,
        #                                         parentLoginPwd=self.loginPwd)

        print("resOpenSlaveCard.json()", resOpenSlaveCard.json())
        assert "200" == resOpenSlaveCard.json()["code"],"开卡测试失败"
        assert "success" == resOpenSlaveCard.json()["message"], "开卡测试失败"
        # 副卡退卡
        reC.returnCardDef(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders, cardNo=startSlaveCardNo)
        # 主卡退卡
        reC.returnCardDef(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders, cardNo=startCardNo)

    def test_openSlaveCardState(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)
        print("resSavaCard.json()  ->", resSavaCard.json())
        # 出库
        cardNos = str(startCardNo) + "," + str(endCardNo)
        print(cardNos)
        amount = len([i for i in range(startCardNo, endCardNo)])
        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)
        print("resFirstOpen", resFirstOpen.json())
        assert "200" == resFirstOpen.json()["code"], "第一次开卡,开卡失败"
        assert "data" in resFirstOpen.json(), "第一次开卡,开卡失败"

        # 副卡入库-出库-开卡
        startSlaveCardNo = int(time.strftime("%y%m%d%H%M%S", time.localtime()))
        endSlaveCardNo = startSlaveCardNo + 1
        resSavaCard = cSI.savaCard(cardHost=self.cardHost, webHeaders=self.webHeaders, startCardNo=startSlaveCardNo,
                                   endCardNo=endSlaveCardNo, cardType=20)
        res = oMC.checkNewCardNo(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders,
                                 cardNo=startSlaveCardNo,
                                 cardType=20)
        assert "20000" == res.json()["code"], "使用已存在未出库的卡片进行校验校验失败"
        assert "该卡状态为[未激活],不能开卡!" == res.json()["message"], "message信息与预期信息不匹配"
        slaveCardNos = str(startSlaveCardNo) + "," + str(endSlaveCardNo)
        amount = len([i for i in range(startSlaveCardNo, endSlaveCardNo + 1)])
        outCardRes = cSO.cardAddOut(cardHost=self.cardHost, webHeaders=self.webHeaders, cardNos=slaveCardNos,
                                    applyUserName=self.applyUserName, applyUserId=self.applyUserId,
                                    applyUserCode=self.applyUserCode, amount=amount)
        assert outCardRes.json()["code"] == "200", "出库失败"
        resOpenSlaveCard = oMC.openSlaveCardDef(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders,
                                                cardNo=startCardNo, slaveCardNo=startSlaveCardNo,
                                                loginPwd=self.loginPwd, applyUserName=self.applyUserName,
                                                parentLoginPwd=self.loginPwd)
        assert "200" == resOpenSlaveCard.json()["code"], "开卡测试失败"
        # 以上为测试准备

        # 卡片不能重复开卡
        resOpenSlaveCard = oMC.openSlaveCardDef(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders,
                                                cardNo=startCardNo, slaveCardNo=startSlaveCardNo,
                                                loginPwd=self.loginPwd, applyUserName=self.applyUserName,
                                                parentLoginPwd=self.loginPwd)
        print("resOpenSlaveCard   ",resOpenSlaveCard.json())
        assert "20000" == resOpenSlaveCard.json()["code"], "开卡测试失败"
        assert "该卡状态为[在用],不能开卡!" == resOpenSlaveCard.json()["message"], "开卡测试失败"

        # 副卡退还后可以重新开卡
        reC.returnCardDef(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders, cardNo=startSlaveCardNo)
        resOpenSlaveCard = oMC.openSlaveCardDef(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders,
                                                cardNo=startCardNo, slaveCardNo=startSlaveCardNo,
                                                loginPwd=self.loginPwd, applyUserName=self.applyUserName,
                                                parentLoginPwd=self.loginPwd)
        assert "200" == resOpenSlaveCard.json()["code"], "开卡测试失败"
        reC.returnCardDef(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders, cardNo=startSlaveCardNo)

        # 主卡密码错误时开卡失败
        resOpenSlaveCard = oMC.openSlaveCardDef(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders,
                                                cardNo=startCardNo, slaveCardNo=startSlaveCardNo,
                                                loginPwd=self.loginPwd, applyUserName=self.applyUserName,
                                                parentLoginPwd="909090")
        assert "10001" == resOpenSlaveCard.json()["code"], "开卡测试失败"
        assert "密码输入有误" == resOpenSlaveCard.json()["message"], "开卡测试失败"

        # 副卡新密码格式不正确-接口暂未校验

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