test_searchByOther.py 9.57 KB
# -*- coding: utf-8 -*-

# @Time    : 2021/8/10 17:33
# @Author  : Ljq
# @File    : test_searchByOther.py
# @Software: PyCharm

"""
进门单列表其他他查询条件
"""

import json
import unittest
from commons.scripts.readConf import rC
from commons.api import zcApi as zcA
from commons.basic import getLookupList as gLL
from commons.ConfigDB import mysql_selectAll as msa
from commons.api.entranceFeeBillList import operationDoUndo as oDU
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")
        carTypeList = gLL.get_LookupList(host=cls.jmsfHost,providerName="车型").json()[1:]
        categoryList = gLL.get_LookupList(host=cls.jmsfHost, providerName="货物品类").json()[1:]
        authDepartmentList = zcA.get_dep(cls.gatewayHost).json()["data"]
        entranceFeeBillTypeList = gLL.get_LookupList(host=cls.jmsfHost, providerName="称重类型").json()[1:]
        entranceFeeBillStateList = gLL.get_LookupList(host=cls.jmsfHost, providerName="状态").json()[1:]
        tradeTypeList = gLL.get_LookupList(host=cls.jmsfHost, providerName="交易类型").json()[1:]
        cls.carType = random.sample(carTypeList, 1)[0]
        cls.category = random.sample(categoryList, 1)[0]
        cls.authDepartment = random.sample(authDepartmentList, 1)[0]
        cls.entranceFeeBillType = random.sample(entranceFeeBillTypeList, 1)[0]
        cls.entranceFeeBillState = random.sample(entranceFeeBillStateList, 1)[0]
        cls.tradeType = random.sample(tradeTypeList, 1)[0]

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

    def test_searchByCardTepy(self):
        """进门单列表-查询:收费单号查询测试"""
        print(self.carType)
        cre_res = zcA.create_jmsf(host=self.gatewayHost,carTypeName=self.carType["text"])
        number = cre_res.json()["data"]["number"]
        resListPage = eFBL.listPage(host=self.jmsfHost,carTypeId=self.carType["value"])
        print(resListPage.json())
        carTypeList=list(set([i["carTypeName"] for i in resListPage.json()["rows"]]))
        assert resListPage.json()["rows"][0]["number"] == number,"车型查询失败查询失败"
        assert len(carTypeList) == 1,"车型查询失败查询失败"
        assert self.carType["text"]==carTypeList[0],"车型查询失败查询失败"

    def test_searchBycategory(self):
        """进门单列表-查询:品类查询测试"""
        goods="雪莲果"
        categoryId = "14436"
        cre_res = zcA.create_jmsf(host=self.gatewayHost,keyword=goods)
        number = cre_res.json()["data"]["number"]
        resListPage = eFBL.listPage(host=self.jmsfHost,categoryId=categoryId)
        print(resListPage.json())
        assert resListPage.json()["rows"][0]["number"] == number,"车型查询失败查询失败"

    def test_searchByProductName(self):
        """进门单列表-查询:商品查询测试"""
        productName = "蔬菜"
        productId = gLL.get_product(self.jmsfHost,productName=productName).json()["data"][0]["id"]
        print(productId)
        cre_res = zcA.create_jmsf(host=self.gatewayHost,keyword=productName)
        number = cre_res.json()["data"]["number"]
        resListPage = eFBL.listPage(host=self.jmsfHost,productName=productName,productId=productId)
        print(resListPage.json())
        productNameList=list(set([i["productName"] for i in resListPage.json()["rows"]]))
        assert resListPage.json()["rows"][0]["number"] == number,"车型查询失败查询失败"
        assert len(productNameList) == 1,"车型查询失败查询失败"
        assert productName==productNameList[0],"车型查询失败查询失败"

    def test_searchByDepartment(self):
        """进门单列表-查询:部门查询查询测试"""
        print(self.authDepartment)
        print(self.authDepartment["name"])
        cre_res = zcA.create_jmsf(host=self.gatewayHost,depName=self.authDepartment["name"])
        number = cre_res.json()["data"]["number"]
        resListPage = eFBL.listPage(host=self.jmsfHost,dep=self.authDepartment["id"])
        # print(resListPage.json())
        depNameList=list(set([i["depName"] for i in resListPage.json()["rows"]]))
        assert resListPage.json()["rows"][0]["number"] == number,"车型查询失败查询失败"
        assert len(depNameList) == 1,"车型查询失败查询失败"
        assert self.authDepartment["name"]==depNameList[0],"车型查询失败查询失败"

    def test_searchByBillType(self):
        """进门单列表-查询:交易类型查询测试"""
        resListPage = eFBL.listPage(host=self.jmsfHost,type="1")
        print(resListPage.json())
        resList=list(set([i["type"] for i in resListPage.json()["rows"]]))
        assert len(resList) == 1,"车型查询失败查询失败"
        assert "整车"==resList[0],"车型查询失败查询失败"

    def test_searchByStatus(self):
        """进门单列表-查询:交易状态查询测试"""
        status = "4"
        cre_res = zcA.create_jmsf(host=self.gatewayHost,carTypeName=self.carType["text"])
        number = cre_res.json()["data"]["number"]
        resListPage = eFBL.listPage(host=self.jmsfHost,status=status)
        print(resListPage.json())
        statusList=list(set([i["status"] for i in resListPage.json()["rows"]]))
        assert resListPage.json()["rows"][0]["number"] != number,"车型查询失败查询失败"
        assert len(statusList) == 1,"车型查询失败查询失败"
        assert "已缴费"==statusList[0],"车型查询失败查询失败"

    def test_searchByTradeType(self):
        """进门单列表-查询:交易类型查询测试"""
        print(self.tradeType)
        cre_res = zcA.create_jmsf(host=self.gatewayHost,transactionName=self.tradeType["text"])
        number = cre_res.json()["data"]["number"]
        resListPage = eFBL.listPage(host=self.jmsfHost,tradeTypeId=self.tradeType["value"])
        print(resListPage.json())
        carTypeList=list(set([i["tradeTypeName"] for i in resListPage.json()["rows"]]))
        assert resListPage.json()["rows"][0]["number"] == number,"车型查询失败查询失败"
        assert len(carTypeList) == 1,"车型查询失败查询失败"
        assert self.tradeType["text"]==carTypeList[0],"车型查询失败查询失败"

    def test_searchByCreatedTime(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)
        createdTime = eFBL.listPage(host=self.jmsfHost,attrValue=number).json()["rows"][0]["created"]
        resListPage = eFBL.listPage(host=self.jmsfHost,startTime=createdTime,endTime=createdTime)
        print(resListPage.json())
        createdTimeList = list(set([i["created"] for i in resListPage.json()["rows"]]))
        assert len(createdTimeList) == 1,"进场时间查询失败"
        assert createdTimeList[0]==createdTime,"进场时间查询失败"

    def test_searchByPaymentTime(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)
        createdTime = eFBL.listPage(host=self.jmsfHost,attrValue=number).json()["rows"][0]["paymentTime"]
        resListPage = eFBL.listPage(host=self.jmsfHost,startPayTime=createdTime,endPayTime=createdTime)
        print(resListPage.json())
        createdTimeList = list(set([i["paymentTime"] for i in resListPage.json()["rows"]]))
        assert len(createdTimeList) == 1,"缴费时间查询测试失败"
        assert createdTimeList[0]==createdTime,"缴费时间查询测试失败"

    def test_searchByRefundTime(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"]
        res_pay = eFBL.do_payOrder(host=self.jmsfHost,attrValue=number)
        time.sleep(3)
        res_undo = oDU.do_undoOrder(host=self.jmsfHost,attrValue=number)
        refundTime = msa(f'SELECT efbd.operator_time FROM entrance_fee_bill efb JOIN entrance_fee_bill_detail efbd ON efb.id=efbd.bill_id WHERE efb.number="{number}";')[0][0]
        resListPage = eFBL.listPage(host=self.jmsfHost, startRefundTime=refundTime, endRefundTime=refundTime)
        assert resListPage.json()["rows"][0]["number"]==number,"退款时间查询失败"
        refundNumberList = list(set([i["number"] for i in resListPage.json()["rows"]]))
        res_msa = [i[0] for i in msa(f'SELECT efb.number FROM entrance_fee_bill efb JOIN entrance_fee_bill_detail efbd ON efb.id=efbd.bill_id WHERE efbd.operator_time="{refundTime}";')]
        assert res_msa.sort()==refundNumberList.sort(),"查询结果与数据库结果不一致"





    """
    三个时间查询暂不涉及
    """