test_batch.py 6.43 KB
# -*- coding: utf-8 -*-

# @Time    : 2021/9/10 10:17
# @Author  : Ljq
# @File    : test_batch.py
# @Software: PyCharm

"""
杭果市场-结算管理-批号管理
"""

from commons.MySession import sessionHg as session
from commons.api.hg.CheckIn import CheckIn
from commons.api.hg.settlement import batch
from commons.scripts.readConf import rC
import unittest,random

class test_batch(unittest.TestCase):
    """杭果市场-结算管理-批号管理"""
    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", "hg_cardNumRe_01")

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

    def test_searchState_1(self):
        """
        批号管理--查询--输入【在售】状态的完整批号,查询出该批号下的相关数据
        """
        # 创建初始数据
        resBatchCode = CheckIn.create_registerRecord(session=session, host=self.gatewayHost,ic=self.ic)
        self.batchCode = resBatchCode.json()["data"]["batchCode"]
        # 执行查询
        print("test_searchState_1 --> self.batchCode:",self.batchCode)
        resSearchState = batch.batchCodeQuery(session=session,host=self.gatewayHost,batchCode=self.batchCode)
        print(resSearchState.json())
        assert resSearchState.json()["code"] == "200","在售状态的登记单查询失败"
        assert resSearchState.json()["state"] == 1,"在售状态的登记单查询失败"
        assert resSearchState.json()["data"]["state"] == 1, "在售状态的登记单查询失败"
        assert resSearchState.json()["data"]["batchCode"] == self.batchCode, "在售状态的登记单查询失败"

    def test_searchState_2(self):
        """
        批号管理--查询--输入【关闭】状态的完整批号,查询出该批号下的相关数据
        """
        # 创建初始数据
        resBatchCode = CheckIn.create_registerRecord(session=session, host=self.gatewayHost,ic=self.ic)
        self.batchCode = resBatchCode.json()["data"]["batchCode"]
        print("test_searchState_1 --> self.batchCode:", self.batchCode)
        # 将批号关闭
        resChange = batch.changeBatchCodeState(session=session,host=self.gatewayHost,batchCode=self.batchCode)
        assert resChange.json()["message"] == "success","批号关闭成功"
        # 执行查询
        resSearchState = batch.batchCodeQuery(session=session,host=self.gatewayHost,batchCode=self.batchCode)
        print(resSearchState.json())
        assert resSearchState.json()["code"] == "200","在售状态的登记单查询失败"
        assert resSearchState.json()["state"] == 2,"在售状态的登记单查询失败"
        assert resSearchState.json()["data"]["state"] == 2, "在售状态的登记单查询失败"
        assert resSearchState.json()["data"]["batchCode"] == self.batchCode, "在售状态的登记单查询失败"

    def test_batchDetails(self):
        """
        批号管理--列表--【列表】中数据显示正确
        """
        # 创建初始数据
        goodsName="西瓜"
        weight = random.randint(50,100)
        print("weight",weight)
        resBatchCode = CheckIn.create_registerRecord(session=session, host=self.gatewayHost,ic=self.ic,goodsName=goodsName,
                                                     weight=weight)
        self.batchCode = resBatchCode.json()["data"]["batchCode"]
        print("test_searchState_1 --> self.batchCode:", self.batchCode)
        # 执行查询
        resSearchState = batch.batchCodeQuery(session=session,host=self.gatewayHost,batchCode=self.batchCode)
        print(resSearchState.json())
        assert resSearchState.json()["code"] == "200","查询状态码返回错误"
        assert resSearchState.json()["data"]["batchCode"] == self.batchCode, "查询获得订单与实际订单不一致"
        assert resSearchState.json()["data"]["registerDetail"][0]["categoryName"] == goodsName, "批号的商品信息与创建时不一致"
        assert resSearchState.json()["data"]["registerDetail"][0]["weight"] == weight, "批号的重量信息与创建时不一致"

    def test_changeState_1(self):
        """
        批号管理--恢复交款--“关闭”状态的批号,可【恢复交款】成功
        """
        # 创建初始数据
        resBatchCode = CheckIn.create_registerRecord(session=session, host=self.gatewayHost,ic=self.ic)
        self.batchCode = resBatchCode.json()["data"]["batchCode"]
        print("test_searchState_1 --> self.batchCode:", self.batchCode)
        # 将批号关闭
        resChange = batch.changeBatchCodeState(session=session,host=self.gatewayHost,batchCode=self.batchCode,state=2)
        assert resChange.json()["message"] == "success","批号关闭成功"
        resChange = batch.changeBatchCodeState(session=session,host=self.gatewayHost,batchCode=self.batchCode,state=1)
        assert resChange.json()["message"] == "success","批号关闭成功"
        # 执行查询
        resSearchState = batch.batchCodeQuery(session=session,host=self.gatewayHost,batchCode=self.batchCode)
        print(resSearchState.json())
        assert resSearchState.json()["data"]["state"] == 1, "在售状态的登记单查询失败"
        assert resSearchState.json()["data"]["batchCode"] == self.batchCode, "在售状态的登记单查询失败"

    def test_changeState_2(self):
        """
        批号管理--恢复交款--“在售”状态的批号,可【停止交款】成功
        """
        # 创建初始数据
        resBatchCode = CheckIn.create_registerRecord(session=session, host=self.gatewayHost,ic=self.ic)
        self.batchCode = resBatchCode.json()["data"]["batchCode"]
        print("test_searchState_1 --> self.batchCode:", self.batchCode)
        # 将批号关闭
        resChange = batch.changeBatchCodeState(session=session,host=self.gatewayHost,batchCode=self.batchCode,state=2)
        assert resChange.json()["message"] == "success","批号关闭成功"
        # 执行查询
        resSearchState = batch.batchCodeQuery(session=session,host=self.gatewayHost,batchCode=self.batchCode)
        print(resSearchState.json())
        assert resSearchState.json()["data"]["state"] == 2, "在售状态的登记单查询失败"
        assert resSearchState.json()["data"]["batchCode"] == self.batchCode, "在售状态的登记单查询失败"