test_tms_myrequest1.py
7.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/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_tms_myrequest(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.dict={}
cls.se=my.getSession(True)
# @unittest.skip("debug")
def test_01_saveOrUpdate(self):
#创建客户单必加test_
url=com.get_api_config('saveOrUpdate', 'saveOrUpdate01', 'url')
header01=json.loads(com.get_api_config('saveOrUpdate', 'saveOrUpdate01', 'update_header01'))
header02=json.loads(com.get_api_config('saveOrUpdate', 'saveOrUpdate01', 'update_header02'))
body=json.loads(com.get_api_config('saveOrUpdate', 'saveOrUpdate01', 'body'))
expect_response=json.loads(com.get_api_config('saveOrUpdate', 'saveOrUpdate01', 'expect_response'))
self.se.headers.update(header01)
self.se.headers.update(header02)
r=my.post(url,data=body,allow_redirects=False)
self.assertEqual(r.json()["code"], "200","first request failed")
self.assertEqual(com.compare_json(r.json(),expect_response),None,"json compare failed")
print(r.json())
self.dict["customerOrderNum"]=db.mysql_selectOne("SELECT `code` FROM `customer_order` WHERE id='%d';"%r.json()['data'])[0]
@unittest.skipDepend(depend="test_01_saveOrUpdate")
def test_02_customerOrderSubmit(self):
#客户单拆单为承运单
url=com.get_api_config('customerOrderSubmit', 'customerOrderSubmit01', 'url')
header01=json.loads(com.get_api_config('customerOrderSubmit', 'customerOrderSubmit01', 'update_header01'))
body=json.loads(com.get_api_config('customerOrderSubmit', 'customerOrderSubmit01', 'body'))
body[0]["code"]=self.dict["customerOrderNum"]
body[1]["code"]=self.dict["customerOrderNum"]
self.se.headers.update(header01)
r=my.post(url,data=json.dumps(body))
self.assertEqual(r.json()["code"], "200")
print(r.json())
self.dict["undertakeOrderID1"]=db.mysql_selectOne('SELECT id FROM `undertake_order` WHERE `code` ="%s";'%r.json()['data'][0])[0]
self.dict["undertakeOrderID2"]=db.mysql_selectOne('SELECT id FROM `undertake_order` WHERE `code` ="%s";'%r.json()['data'][1])[0]
print(self.dict)
@unittest.skipDepend(depend="test_02_customerOrderSubmit")
def test_03_undertaskOrderSubmit(self):
#承运单合成货单
url=com.get_api_config('undertaskOrderSubmit', 'undertaskOrderSubmit01', 'url')
header01=json.loads(com.get_api_config('undertaskOrderSubmit', 'undertaskOrderSubmit01', 'update_header01'))
body=json.loads(com.get_api_config('undertaskOrderSubmit', 'undertaskOrderSubmit01', 'body'))
body['ids'][1]=self.dict["undertakeOrderID1"]
body['ids'][2]=self.dict["undertakeOrderID2"]
self.se.headers.update(header01)
r=my.post(url,data=json.dumps(body))
self.assertEqual(r.json()["code"], "200")
print(r.json())
self.dict["transportOrderID"]=db.mysql_selectOne("SELECT `id` FROM `transport_order` WHERE firm_code = 'CC201905200058' ORDER BY id DESC LIMIT 1;")[0]
self.dict["undertakeGoodsID"]=db.mysql_selectOne("SELECT `id` FROM undertake_goods ORDER BY id DESC LIMIT 1;")[0]
@unittest.skipDepend(depend="test_03_undertaskOrderSubmit")
def test_04_updateTransportOrderLoaded(self):
#货单进行发货
url=com.get_api_config('updateTransportOrderLoaded', 'updateTransportOrderLoaded01', 'url')
header01=json.loads(com.get_api_config('updateTransportOrderLoaded', 'updateTransportOrderLoaded01', 'update_header01'))
body=json.loads(com.get_api_config('updateTransportOrderLoaded', 'updateTransportOrderLoaded01', 'body'))
body['id']=self.dict["transportOrderID"]
body['undertTakeGoodsUpdateDtoList[0].goodsId']=(self.dict["undertakeGoodsID"]-1)
body['undertTakeGoodsUpdateDtoList[1].goodsId']=self.dict["undertakeGoodsID"]
self.se.headers.update(header01)
r=my.post(url,data=body)
self.assertEqual(r.json()["code"], "200")
print(r.json())
@unittest.skipDepend(depend="test_04_updateTransportOrderLoaded")
def test_05_departTransportOrder(self):
#货单进行发车
url=com.get_api_config('departTransportOrder', 'departTransportOrder01', 'url')
body=json.loads(com.get_api_config('departTransportOrder', 'departTransportOrder01', 'body'))
body['id']=self.dict["transportOrderID"]
r=my.post(url,data=body)
self.assertEqual(r.json()["code"], "200")
print(r.json())
@unittest.skipDepend(depend="test_05_departTransportOrder")
def test_06_arrivalUnderTakeOrder(self):
#货单1到货登记
url=com.get_api_config('arrivalUnderTakeOrder', 'arrivalUnderTakeOrder01', 'url')
url_dict=com.get_to_post(url)
url_dict[[key for key in url_dict.keys() if "code" in key][0]]= db.mysql_selectOne("SELECT `code` FROM `undertake_order` where id ={};".format(self.dict["undertakeOrderID1"]))[0]
url=com.post_to_get(url_dict)
r=my.get(url)
self.assertEqual(r.json()["code"], "200")
print(r.json())
@unittest.skipDepend(depend="test_06_arrivalUnderTakeOrder")
def test_07_arrivalUnderTakeOrder(self):
#货单2到货登记
url=com.get_api_config('arrivalUnderTakeOrder', 'arrivalUnderTakeOrder01', 'url')
url_dict=com.get_to_post(url)
url_dict[[key for key in url_dict.keys() if "code" in key][0]]= db.mysql_selectOne("SELECT `code` FROM `undertake_order` where id ={};".format(self.dict["undertakeOrderID2"]))[0]
url=com.post_to_get(url_dict)
r=my.get(url)
self.assertEqual(r.json()["code"], "200")
print(r.json())
# def tearDown(self):
# print("tearDown")
@classmethod
def tearDownClass(cls):
print(cls.dict)
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)