最近忙的一匹。。。
终于闲下来把现在负责的项目一步一步实现测试自动化
这个配载页面每次手工测都要点好久。。。所以先实现配载页面的接口自动化。。嗯,waybillNo字段可以写个自增或者随机组合(需要校验,已存在则重新生成,直到生成的是新的主单号)
import requests
import json
import random_waybillno
def test_peizai_add():
param = {'userName' :'zhangcq','password' :'c4ca4238a0b923820dcc509a6f75849b'}
header1 = {"Content-Type":"application/json;charset=UTF-8"}
r1 = requests.post('http://10.9.38.25:8086/api/sys/login/submit',headers = header1,json= param)
print(r1.text)
print(r1.status_code)
dict1 = json.loads(r1.text)
print(dict1)
token = dict1['result']
url ="http://10.9.38.25:8086/api/order/delivery/save"
headers2 = {"Content-Type":"application/json","Authentication-Token":token}
data = {
"airportDepartureCode":"SHA",
"airportDestinationCode":"KMG",
"batchNo":"fhd_2097",
"chargeableWeight":1000,
"consignee":"张星星收件",
"consigneeAddress":"收件地址",
"consigneeCode":"87100",
"consigneeTel":"17612166446",
"customer":"张星星发件",
"customerAddress":"发件地址",
"customerCode":"02199",
"customerTel":"15090653560",
"fileList": [
{
"name":"timg.jpg",
"url":"https://fs.zto.com/fs1/M03/F9/36/wKhBFlvPyWyAPnVVAATMfSGFQaI433.jpg"
}
],
"flightDate":"2018-10-25T01:06:11.783Z",
"flightNo":"MU5806",
"goodsDescription":"衣服",
"goodsType":"1",
"grossWeight":1000,
"loadCount":15,
"loadFlightDate":"2018-10-25T01:06:11.783Z",
"loadFlightNo":"MU5806",
"loadNo":"",
"loadType":"1",
"loadWeight":200,
"pcsNo":500,
"preLoadNo":"null",
"routeType":"DIRECT",
"scheduledArrivalTime":"15:06",
"scheduledDepartureTime":"17:06",
"transferFlightDate":"2018-10-25T14:38:20.111Z",
"transferFlightNo":"null",
"waybillNo": random_waybillno.connect_mysql()
}
r2 = requests.post(url = url,json = data,headers = headers2)
print(r2.text)
print(r2.status_code)
if __name__ =='__main__':
test_peizai_add()
执行python文件后,查看数据库,数据添加成功
查看日志
2.主单号waybillNo随机获取,并校验数据库中是否已存在,如果存在则重新生成
文件名:random_waybillno.py
import random
import pymysql
def random_no(a):
id = []
id =''.join(str(i)for iin random.sample(range(0, 9), a))
return id
def waybill_no():
str ='%s-%s' % (random_no(3),random_no(8))
return str
def connect_mysql():
s = waybill_no()
conn = pymysql.connect(host ="10.9.38.26",port =3306,user ="root",passwd ="1qaz2wsx",db ="starunion_order",charset="utf8")
cur = conn.cursor()
cur.execute("select * from freight_master_air_waybill where mawb_no = %s",s)
tuple1 = cur.fetchall()
len_tuple1 =len(tuple1)
if len_tuple1 ==0:
return s
else:
connect_mysql()
if __name__ =='__main__':
connect_mysql()