test_BackCollection.py 4.43 KB
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import unittest
from  commons import common as com
from commons import ConfigDB as db
from commons.MySession import my,hg
from commons.api.hg.BackCollection.tradingOrder_create import tradingOrder_create
from commons.api.hg.BackCollection.tradingOrder_getUnPaidByCode import tradingOrder_getUnPaidByCode
from commons.api.hg.BackCollection.tradingOrder_pay import tradingOrder_pay
from commons.api.hg.BackCollection.tradingOrder_loadPrintData import tradingOrder_loadPrintData
from commons.basic.registerRecord_save import registerRecord_save
tc=tradingOrder_create()
tg=tradingOrder_getUnPaidByCode()
tp=tradingOrder_pay()
tl=tradingOrder_loadPrintData()
rs=registerRecord_save()


class test_BackCollection(unittest.TestCase):
    "杭果市场-交易管理"

    @classmethod
    def setUpClass(cls) :
        #新增一个进门批号单
        re=hg.post(url=rs.url,headers=rs.header,json=rs.body1)
        #获取进门批号
        cls.batch=re.json()["data"]["batchCode"]
        # print("setup class",re.json())

    def setUp(self):
        body=tc.body.copy()
        body["orderItemList"][0]["batchCode"]=self.batch
        #创建交款单
        self.re=hg.post(url=tc.url,headers=tc.header,json=body)
        #根据交款单的id查询交款单的code,self.re.json()["data"]为交款单的id
        self.order_code=db.mysql_selectOne(tc.sql.replace("373",str(self.re.json()["data"])))[0]
        # print("setup",self.order_code,self.re.json())

    @unittest.case_mark(my.mark())
    def test_BackCollection_01_getUnPaidByCode(self):
        "后台收款-查询交款单:输入合法交款单号,查询指定交款单"
        #替换批次号
        url=tg.url.replace("2109141500003",self.order_code[0:-1])
        #请求
        re=hg.get(url=url,headers=tg.header)
        print(re.json())
        self.assertTrue(self.order_code in str(re.json()).replace(" ",""))


    @unittest.skipDepend(depend="test_BackCollection_01_search")
    @unittest.case_mark(my.mark())
    def test_BackCollection_02_pay(self):
        "后台收款-交款单支付:应收金额=实收金额,且仅现金收款"
        #修改查询的值
        body=tp.body.copy()
        body["id"] = self.re.json()["data"]
        #请求
        re=hg.post(url=tp.url,headers=tp.header,json=body)
        print(re.json())
        #断言
        self.assertTrue("操作成功" in str(re.json()).replace(" ",""))


    @unittest.skipDepend(depend="test_BackCollection_02_pay")
    @unittest.case_mark(my.mark())
    def test_BackCollection_03_loadPrintData(self):
        "后台收款-打印接口:完成支付后返回打印信息"
        #打印前先调用支付接口,支付成功后才能打印
        body=tp.body.copy()
        body["id"] = self.re.json()["data"]
        hg.post(url=tp.url, headers=tp.header, json=body)
        #支付完成后,测试打印信息接口。修改查询的id
        url=tl.url.replace("398",str(self.re.json()["data"]))
        re=hg.get(url=url,headers=tl.header)
        print(re.json())
        #断言
        self.assertTrue("操作成功" in str(re.json()).replace(" ",""))
        self.assertTrue("交款成交单" in str(re.json()).replace(" ",""))
        self.assertTrue(self.order_code[0:-1] in str(re.json()).replace(" ",""))


    @unittest.skipDepend(depend="test_BackCollection_02_pay")
    @unittest.case_mark(my.mark())
    def test_BackCollection_04_pay(self):
        "后台收款-交款单组合支付:优惠,pos卡,支票一起的组合支付"
        #修改查询的值
        body=tp.body1.copy()
        body["id"] = self.re.json()["data"]
        #请求
        re=hg.post(url=tp.url,headers=tp.header,json=body)
        print(re.json())
        #断言
        self.assertTrue("操作成功" in str(re.json()).replace(" ",""))

    @unittest.skipDepend(depend="test_BackCollection_02_pay")
    @unittest.case_mark(my.mark())
    def test_BackCollection_05_pay(self):
        "后台收款-交款单组合支付:现金,优惠,pos卡,支票一起的组合支付"
        #修改查询的值
        body=tp.body2.copy()
        body["id"] = self.re.json()["data"]
        #请求
        re=hg.post(url=tp.url,headers=tp.header,json=body)
        print(re.json())
        #断言
        self.assertTrue("操作成功" in str(re.json()).replace(" ",""))




if __name__ == "__main__":

    unittest.main(verbosity=2)
    # com.run_one(test_generalCustomerLoan("test_generalCustomerLoan_01_save"))