test_pwdModify.py 19.7 KB
#coding=utf-8

# @Time    : 2021/6/11 14:35
# @Author  : Ljq
# @File    : test_pwdModify.py
# @Software: PyCharm


"""
    
"""

import unittest
import random
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.operatePwd as operatePwd
from commons.readConf import readConfig
from commons.api.doLogin import doLogin

class test_pwdModify(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 producePwd(self):
        pwd = "".join(random.sample("0123456789", 6))
        return pwd

    def test_pwdModify(self):
        """修改密码正向流程测试"""
        # 主卡入库-出库-开卡
        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)
        print("resSavaCard.json()  ->", resSavaCard.json())
        cardNos = str(startCardNo) + "," + str(endCardNo)
        print(cardNos)
        amount = 2
        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 + 2
        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 = 2
        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"], "开卡测试失败"
        # 开卡结束-获取卡片客户信息
        resSimpleInfo = operatePwd.getSimpleInfo(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders,
                                      cardNo=startCardNo)
        customerId,accountId = resSimpleInfo.json()["data"]["accountInfo"]["customerId"],resSimpleInfo.json()["data"]["accountInfo"]["accountId"]
        resSimpleInfo = operatePwd.getSimpleInfo(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders,
                                         cardNo=startSlaveCardNo)
        customerIdSlaveCard, accountIdSlaveCard = resSimpleInfo.json()["data"]["accountInfo"]["customerId"], \
                                                  resSimpleInfo.json()["data"]["accountInfo"]["accountId"]
        # 以上为测试数据准备

        """开始测试"""

        # 主卡正常修改密码
        newPwd = self.producePwd()
        print("newPwd",newPwd)
        resRLP = operatePwd.modifyLoginPwd(gatewayHost=self.gatewayHost,clientHeaders=self.clientHeaders,oldLoginPwd=self.loginPwd,
                                   loginPwd=newPwd,secondLoginPwd=newPwd,cardNo=startCardNo,accountId=accountId,customerId=customerId)
        # print(resRLP.json())
        assert "200" == resRLP.json()["code"],"主卡正常修改密码测试不通过"
        assert "OK" == resRLP.json()["message"], "主卡正常修改密码测试不通过"

        # 副卡正常修改密码
        newPwdSlave = self.producePwd()
        # print("newPwdSlave",newPwdSlave)
        resRLP = operatePwd.modifyLoginPwd(gatewayHost=self.gatewayHost,clientHeaders=self.clientHeaders,oldLoginPwd=self.loginPwd,loginPwd=newPwdSlave,
                               secondLoginPwd=newPwdSlave,cardNo=startSlaveCardNo,accountId=accountIdSlaveCard,customerId=customerIdSlaveCard)
        print(resRLP.json())
        assert "200" == resRLP.json()["code"],"副卡正常修改密码测试不通过"
        assert "OK" == resRLP.json()["message"], "副卡正常修改密码测试不通过"

        """测试完成"""

        # 副卡退卡
        resSlave = reC.returnCardDef(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders, cardNo=startSlaveCardNo,loginPwd=newPwdSlave)
        assert "200" == resSlave.json()["code"],"副卡使用新密码退卡成功,密码修改成功"
        assert "OK" == resSlave.json()["message"], "副卡使用新密码退卡成功,密码修改成功"
        # 主卡退卡
        res = reC.returnCardDef(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders, cardNo=startCardNo,loginPwd=newPwd)
        assert "200" == res.json()["code"],"主卡使用新密码退卡成功,密码修改成功"
        assert "OK" == res.json()["message"], "主卡使用新密码退卡成功,密码修改成功"

    def test_pwdModifyError(self):
        """修改密码异常流程"""
        # 主卡入库-出库-开卡
        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)
        print("resSavaCard.json()  ->", resSavaCard.json())
        cardNos = str(startCardNo) + "," + str(endCardNo)
        print(cardNos)
        amount = 2
        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 + 2
        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 = 2
        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"], "开卡测试失败"
        # 开卡结束-获取卡片客户信息
        resSimpleInfo = operatePwd.getSimpleInfo(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders,
                                      cardNo=startCardNo)
        customerId,accountId = resSimpleInfo.json()["data"]["accountInfo"]["customerId"],resSimpleInfo.json()["data"]["accountInfo"]["accountId"]
        resSimpleInfo = operatePwd.getSimpleInfo(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders,
                                         cardNo=startSlaveCardNo)
        customerIdSlaveCard, accountIdSlaveCard = resSimpleInfo.json()["data"]["accountInfo"]["customerId"], \
                                                  resSimpleInfo.json()["data"]["accountInfo"]["accountId"]
        # 以上为测试数据准备

        """开始测试"""

        # 副卡原密码错误修改失败
        newPwdSlave = self.producePwd()
        resRLP = operatePwd.modifyLoginPwd(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders, oldLoginPwd="909090",
                                   loginPwd=newPwdSlave,
                                   secondLoginPwd=newPwdSlave, cardNo=startSlaveCardNo, accountId=accountIdSlaveCard,
                                   customerId=customerIdSlaveCard)
        assert "10001" == resRLP.json()["code"], "副卡原密码错误修改失败测试不通过"
        assert "密码输入有误" == resRLP.json()["message"], "副卡原密码错误修改失败测试不通过"
        resSlave = reC.returnCardDef(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders,
                                     cardNo=startSlaveCardNo, loginPwd=newPwdSlave)
        assert "10001" == resSlave.json()["code"], "修改密码失败后不能使用新密码退卡,测试不通过"
        # 主卡原密码错误修改失败
        newPwd = self.producePwd()
        resRLP = operatePwd.modifyLoginPwd(gatewayHost=self.gatewayHost,clientHeaders=self.clientHeaders,oldLoginPwd="909090",
                                   loginPwd=newPwd,secondLoginPwd=newPwd,cardNo=startCardNo,accountId=accountId,customerId=customerId)
        assert "10001" == resRLP.json()["code"],"主卡原密码错误修改失败测试不通过"
        assert "密码输入有误" == resRLP.json()["message"], "主卡原密码错误修改失败测试不通过"
        res = reC.returnCardDef(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders, cardNo=startCardNo,
                                loginPwd=newPwd)
        assert "10001" == res.json()["code"], "修改密码失败后不能使用新密码退卡,测试不通过"

        # 两次输入的新密码不一致时修改密码失败
        newPwdSlave = self.producePwd()
        resRLP = operatePwd.modifyLoginPwd(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders, oldLoginPwd=self.loginPwd,
                                   loginPwd="909090",secondLoginPwd=newPwdSlave, cardNo=startSlaveCardNo,
                                   accountId=accountIdSlaveCard, customerId=customerIdSlaveCard)
        print(resRLP.json())
        assert "2000" == resRLP.json()["code"], "副卡两次输入的新密码不一致时修改密码失败测试不通过"
        assert "两次输入密码不匹配" == resRLP.json()["message"], "副卡两次输入的新密码不一致时修改密码失败测试不通过"
        resSlave = reC.returnCardDef(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders,
                                     cardNo=startSlaveCardNo, loginPwd=newPwdSlave)
        assert "10001" == resSlave.json()["code"], "修改密码失败后不能使用新密码退卡,测试不通过"
        # 主卡原密码错误修改失败
        newPwd = self.producePwd()
        resRLP = operatePwd.modifyLoginPwd(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders, oldLoginPwd=self.loginPwd,
                                   loginPwd="909090", secondLoginPwd=newPwd, cardNo=startCardNo, accountId=accountId,
                                   customerId=customerId)
        print(resRLP.json())
        assert "2000" == resRLP.json()["code"], "主卡两次输入的新密码不一致时修改密码失败测试不通过"
        assert "两次输入密码不匹配" == resRLP.json()["message"], "主卡两次输入的新密码不一致时修改密码失败测试不通过"
        res = reC.returnCardDef(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders, cardNo=startCardNo,
                                loginPwd=newPwd)
        assert "10001" == res.json()["code"], "修改密码失败后不能使用新密码退卡,测试不通过"

        # 第一个密码输入长度不满足六位时修改失败
        newPwdSlave = self.producePwd()
        resRLP = operatePwd.modifyLoginPwd(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders, oldLoginPwd=self.loginPwd,
                                   loginPwd="90909",secondLoginPwd=newPwdSlave, cardNo=startSlaveCardNo,
                                   accountId=accountIdSlaveCard, customerId=customerIdSlaveCard)
        print(resRLP.json())
        assert "1000" == resRLP.json()["code"], "副卡第一个密码输入长度不满足六位时修改失败测试不通过"
        assert "密码必须6位" == resRLP.json()["message"], "副卡第一个密码输入长度不满足六位时修改失败测试不通过"
        resSlave = reC.returnCardDef(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders,
                                     cardNo=startSlaveCardNo, loginPwd=newPwdSlave)
        assert "10001" == resSlave.json()["code"], "修改密码失败后不能使用新密码退卡,测试不通过"
        # 主卡原密码错误修改失败
        newPwd = self.producePwd()
        resRLP = operatePwd.modifyLoginPwd(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders, oldLoginPwd=self.loginPwd,
                                   loginPwd="90909", secondLoginPwd=newPwd, cardNo=startCardNo, accountId=accountId,
                                   customerId=customerId)
        print(resRLP.json())
        assert "1000" == resRLP.json()["code"], "主卡第一个密码输入长度不满足六位时修改失败测试不通过"
        assert "密码必须6位" == resRLP.json()["message"], "主卡第一个密码输入长度不满足六位时修改失败测试不通过"
        res = reC.returnCardDef(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders, cardNo=startCardNo,
                                loginPwd=newPwd)
        assert "10001" == res.json()["code"], "修改密码失败后不能使用新密码退卡,测试不通过"

        # 第二个密码输入长度不满足六位时修改失败
        newPwdSlave = self.producePwd()
        resRLP = operatePwd.modifyLoginPwd(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders,
                                   oldLoginPwd=self.loginPwd,
                                   loginPwd=newPwdSlave, secondLoginPwd="90909", cardNo=startSlaveCardNo,
                                   accountId=accountIdSlaveCard, customerId=customerIdSlaveCard)
        print(resRLP.json())
        assert "1000" == resRLP.json()["code"], "副卡第二个密码输入长度不满足六位时修改失败测试不通过"
        assert "确认密码密码必须6位" == resRLP.json()["message"], "副卡第二个密码输入长度不满足六位时修改失败测试不通过"
        resSlave = reC.returnCardDef(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders,
                                     cardNo=startSlaveCardNo, loginPwd=newPwdSlave)
        assert "10001" == resSlave.json()["code"], "修改密码失败后不能使用新密码退卡,测试不通过"
        # 主卡原密码错误修改失败
        newPwd = self.producePwd()
        resRLP = operatePwd.modifyLoginPwd(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders,
                                   oldLoginPwd=self.loginPwd,
                                   loginPwd=newPwd, secondLoginPwd="90909", cardNo=startCardNo, accountId=accountId,
                                   customerId=customerId)
        print(resRLP.json())
        assert "1000" == resRLP.json()["code"], "主卡第二个密码输入长度不满足六位时修改失败测试不通过"
        assert "确认密码密码必须6位" == resRLP.json()["message"], "主卡第二个密码输入长度不满足六位时修改失败测试不通过"
        res = reC.returnCardDef(gatewayHost=self.gatewayHost, clientHeaders=self.clientHeaders, cardNo=startCardNo,
                                loginPwd=newPwd)
        assert "10001" == res.json()["code"], "修改密码失败后不能使用新密码退卡,测试不通过"

        """测试完成"""

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