test_searchByAttrName.py 6.56 KB
# -*- coding: utf-8 -*-

# @Time    : 2021/8/10 15:32
# @Author  : Ljq
# @File    : test_searchByAttrName.py
# @Software: PyCharm

"""
进门单列表查询
"""


import json
import unittest
from commons.scripts.readConf import rC
from commons.api import zcApi as zcA
from commons import ConfigDB as CoDB
from commons.MySession import my
from commons.api.entranceFeeBillList import entranceFeeBillList as eFBL
import time,random

class test_listPage(unittest.TestCase):
    """哈尔滨市场-进门单列表:attr进门单属性查询测试"""
    def setUp(self) -> None:
        pass

    def tearDown(self) -> None:
        pass


    @classmethod
    def setUpClass(cls) -> None:
        cls.gatewayHost = rC.returnOptionsItems("host", "gatewayHost")
        cls.jmsfHost = rC.returnOptionsItems("host", "jmsfHost")
        cls.ic = rC.returnOptionsItems("testInfo", "cardNumRe")

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

    def test_searchByNumber(self):
        """进门单列表-查询:收费单号查询测试"""
        plate = f"川A{random.randint(10000, 99999)}"
        goods = "树番茄"
        cre_res = zcA.create_jmsf(host=self.gatewayHost,plate=plate,keyword=goods)
        number = cre_res.json()["data"]["number"]
        resListPage = eFBL.listPage(host=self.jmsfHost,attrValue=number)
        print(resListPage.json())
        assert resListPage.json()["rows"][0]["number"] == number,"按照收费单号查询失败"
        assert len(resListPage.json()["rows"]) == 1,"按照收费单号查询失败"

    def test_searchByPlate(self):
        """进门单列表-查询:车牌号查询测试"""
        plate = f"川A{random.randint(10000, 99999)}"
        goods = "雪莲果"
        cre_res = zcA.create_jmsf(host=self.gatewayHost,plate=plate,keyword=goods)
        resListPage = eFBL.listPage(host=self.jmsfHost,attrName="车号",attrValue=plate)
        print(resListPage.json())
        assert resListPage.json()["rows"][0]["plate"] == plate,"按照车牌号查询失败"

    def test_searchByGoods(self):
        """进门单列表-查询:商品查询测试"""
        goods = "树番茄"
        cre_res = zcA.create_jmsf(host=self.gatewayHost,keyword=goods)
        resListPage = eFBL.listPage(host=self.jmsfHost,attrName="商品",attrValue=goods)
        print(resListPage.json())
        assert resListPage.json()["rows"][0]["productName"] == goods,"按照商品查询失败"

    def test_searchByTollman(self):
        """进门单列表-查询:收费员查询测试"""
        plate = f"川A{random.randint(10000, 99999)}"
        goods = "雪莲果"
        userName = "hd_test"
        cre_res = zcA.create_jmsf(host=self.gatewayHost,plate=plate,keyword=goods,userName=userName)
        number = cre_res.json()["data"]["number"]
        # 进门单缴费
        eFBL.do_payOrder(host=self.jmsfHost,attrValue=number,ic=self.ic)
        payUser = my.userInfo["data"]["user"]["realName"]
        resListPage = eFBL.listPage(host=self.jmsfHost,attrName="收费员",attrValue=payUser)
        numberList = [i["number"] for i in resListPage.json()["rows"]]
        numberStr = ",".join(numberList)
        # 缴费状态验证
        assert resListPage.json()["rows"][0]["status"] == "已缴费","收费状态错误"
        # 查询结果验证
        cashier_name = CoDB.mysql_selectAll(f'SELECT cashier_name FROM entrance_fee_bill WHERE number in ({numberStr})')
        cashier_name_list = [i[0] for i in cashier_name]
        assert cashier_name_list[0] == payUser, "按照收费员查询失败"

    def test_searchByCname(self):
        """进门单列表-查询:客户名称查询测试"""
        ic = self.ic
        cName = eFBL.get_icCheck(host=self.jmsfHost,ic=ic).json()["data"]["aInfo"]["customerName"]
        # 创建进门单
        plate = f"川A{random.randint(10000, 99999)}"
        goods = "雪莲果"
        cre_res = zcA.create_jmsf(host=self.gatewayHost,plate=plate,keyword=goods)
        number = cre_res.json()["data"]["number"]
        # 进门单缴费
        eFBL.do_payOrder(host=self.jmsfHost,attrValue=number,ic=ic)
        resListPage = eFBL.listPage(host=self.jmsfHost,attrName="客户姓名",attrValue=cName)
        print(resListPage.json())
        cNameList = list(set([i["customerName"] for i in resListPage.json()["rows"]]))
        print(cNameList)
        # 缴费状态验证
        assert resListPage.json()["rows"][0]["status"] == "已缴费","按照客户姓名查询失败"
        assert len(cNameList)==1,"按照客户姓名查询失败"
        assert cName == cNameList[0], "按照客户姓名查询失败"

    def test_searchByIc(self):
        """进门单列表-查询:客户卡号查询测试"""
        ic = self.ic
        # 创建进门单
        plate = f"川A{random.randint(10000, 99999)}"
        goods = "雪莲果"
        cre_res = zcA.create_jmsf(host=self.gatewayHost,plate=plate,keyword=goods)
        number = cre_res.json()["data"]["number"]
        eFBL.do_payOrder(host=self.jmsfHost,attrValue=number,ic=ic)
        resListPage = eFBL.listPage(host=self.jmsfHost,attrName="客户卡号",attrValue=ic)
        print(resListPage.json())
        icList = list(set([i["ic"] for i in resListPage.json()["rows"]]))
        print(icList)
        # 缴费状态验证
        assert resListPage.json()["rows"][0]["status"] == "已缴费","按照客户卡号查询失败"
        assert len(icList)==1,"按照客户卡号查询失败"
        assert ic == icList[0], "按照客户卡号查询失败"

    def test_searchByPhone(self):
        """进门单列表-查询:手机号码询测试"""
        ic = self.ic
        cPhone = eFBL.get_icCheck(host=self.jmsfHost,ic=ic).json()["data"]["aInfo"]["customerContactsPhone"]
        # 创建进门单并缴费
        plate = f"川A{random.randint(10000, 99999)}"
        goods = "雪莲果"
        cre_res = zcA.create_jmsf(host=self.gatewayHost,plate=plate,keyword=goods)
        number = cre_res.json()["data"]["number"]
        eFBL.do_payOrder(host=self.jmsfHost,attrValue=number,ic=ic)
        # 查询进门单
        resListPage = eFBL.listPage(host=self.jmsfHost,attrName="手机号码",attrValue=cPhone)
        numberList = [i["number"] for i in resListPage.json()["rows"]]
        numberStr = ",".join(numberList)
        cPhoneFromDb = CoDB.mysql_selectAll(f'SELECT customer_phone FROM entrance_fee_bill WHERE number in ({numberStr});')
        cPhoneList = list(set([i[0] for i in cPhoneFromDb]))
        # 缴费状态验证
        assert resListPage.json()["rows"][0]["status"] == "已缴费","按照客户姓名查询失败"
        assert cPhone == cPhoneList[0], "按照客户姓名查询失败"