test_upStream.py 2.98 KB
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import unittest
import json
import urllib3
from commons import ConfigDB as db
from commons import common as com
from commons.MyRequest import myrequest 
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
my=myrequest()

#列表查询
class test_upStream(unittest.TestCase):
    
    @classmethod
    def setUpClass(cls):
        #新增登记单
        cls.se=my.getSession(True)
    #由于可能有多种情况所以使用传统的setup
    def setUp(self):
#         #新增登记单
#         my.registerBill_insert(True)
        pass
    @unittest.case_config(com.mark())
    def test_01_upStream(self):
        #查询上下游企业
        re=my.post2("test_01_upStream")
        print(re.json())

    def test_02_upStream(self):
        #新增理货区进场登记单,获取新增前最新的登记单id
#         code=db.mysql_selectOne('SELECT code FROM `register_bill` WHERE id="{}";'.format(my.temp[0]))[0]
#         #获取接口参数
#         url=com.get_module_config('registerBill', 'listPage', 'listPage01', 'url')
#         header=json.loads(com.get_module_config('registerBill', 'listPage', 'listPage01', 'header'))
#         body=com.get_module_config('registerBill', 'listPage', 'listPage01', 'body')
#         body=body.replace("d2020082700076",code)
#         expect_response=json.loads(com.get_module_config('registerBill', 'listPage', 'listPage01', 'expect_response'))
#         #进行接口请求,两种方式之一data
#         r=my.post(url,data=(body.encode().decode('unicode-escape')),headers=header)
#         print(r.json())
#         #进行接口断言
#         self.assertEqual(r.json()["rows"][0]["code"], code," request failed")
#         self.assertEqual(com.compare_json(r.json(),expect_response),None,"json compare failed")
        pass
    
    def tearDown(self):

        print("tearDown")
        
    @classmethod
    def tearDownClass(cls):
        cls.se.close()

if __name__ == "__main__":
#unittest.main()方法会搜索该模块文件下所有以test开头的测试用例方法,并自动执行它们。
#如果不加下面这个语句,那么在通过unittest的方法添加测试用例时,这个文件里面的用例不会被搜索到。

    unittest.main(verbosity=2)

# #    以下代码可以调试单个测试用例,用例中打印的语句不会展示到控制台,使用前需要注释上面的代码unittest.main(),如果不使用下面代码,
# #    在有unittest.main()的情况下点击ctrl+f11,会直接运行当前页面所有用例,并且把用例用有打印的语句显示到控制台
#     current_suite = unittest.TestSuite()
#     current_suite.addTest(submitOrder("test_01"))
#     #以列表形式添加多个测试用例
# #     current_suite.addTests([submitOrder_With_Coupon("test_01"),submitOrder_With_Coupon("test_02")])
#     # 执行测试
#     runner = unittest.TextTestRunner()
#     #runner.run(可以直接添加测试用例如submitOrder_With_Coupon("test_01"))
#     runner.run(current_suite)