importrequestsimportjsonfrom urllib importparseclassHttpWayBillRquest:'''运单的增改查'''

defaccess_token(self):'''获取token'''url= 'http://xxxxxxxxx.com'username= '12333'password= '12334566'res_json= requests.get(url, auth=(username, password)).json()print('access_token的结果为:\n', res_json)

datas_token= res_json['data']

token_data = datas_token['data']['access_token']

token_type= datas_token['data']['token_type']returntoken_type,token_datadefcreatewaybill(self, datas_create,token_type,token_data):'''创建单条或多条运单申请'''create_url= 'http://xxxxxxxxx.com'header={'Authorization': token_type+ ' ' +token_data,'Content-Type': 'application/json; charset=UTF-8'}

datas_json=eval(datas_create)res= requests.post(url=create_url, json=datas_json, headers=header)print('申请运单响应头:\n', res.headers)print('申请运单响应体:\n', res.text)defupdatewaybill1(self, delivery_id, data_update1,token_type,token_data):'''修改一条运单信息'''update_url1= "http://xxxxxxxxx.com''

header ={'Authorization': token_type + ' ' +token_data,'Content-Type': 'application/json; charset=UTF-8'}

datas_json=eval(data_update1)

res= requests.put(url=update_url1 + delivery_id, json=datas_json, headers=header)print('更新1条运单响应头:\n',res.headers)print('更新1条运单响应体:\n',res.text)defupdatewaybill2(self,data_update2,token_type,token_data):'''更新多条运单信息'''update_url2= 'http://xxxxxxxxx.com/'header={'Authorization': token_type + ' ' +token_data,'Content-Type': 'application/json; charset=UTF-8'}

datas_json=eval(data_update2)

res= requests.put(url=update_url2, json=datas_json, headers=header)print('更新多条运单响应头:\n',res.headers)print('更新多条运单响应体:\n',res.text)deffindwaybill1(self,delivery_id,token_type,token_data):'''查询1条运单信息'''finds_url1= 'http://xxxxxxx.com/'header={'Authorization': token_type + ' ' +token_data,'Content-Type': 'application/json; charset=UTF-8'}

url_finds1= finds_url1 +delivery_idprint('查询1条运单请求头:', header)print('查询1条运单请求url:', url_finds1)

res= requests.get(url=url_finds1, headers=header)print('查询1条运单响应头:\n', res.headers)print('查询1条运单响应体:\n',res.text)deffindwaybill2(self,find_data,token_type,token_data):'''多条件查找运单信息'''finds_url2= "http://xxxxxxxxx.com''

header ={'Authorization': token_type + ' ' +token_data,'Content-Type': 'application/json; charset=UTF-8'}

encode_data=parse.urlencode(find_data)

url_finds2= finds_url2 + '?' +encode_dataprint('多条件查询运单请求头:', header)print('多条件查询运单请求url:', url_finds2)

res= requests.get(url=url_finds2, headers=header)print('多条件查询运单响应头:', res.headers)print('多条件查询运单响应体:', res.text)

主代码:waybill.py

(1)获取token

from waybill.WayBill importHttpWayBillRquest

Waybillrquest=HttpWayBillRquest()

Token=Waybillrquest.access_token()print('token为:{0}\ntoken_type为:{1}\n'.format(Token[1],Token[0]))

结果为:

(2)创建运单信息

importrandomimporttimefrom waybill.WayBill importHttpWayBillRquest'''创建单笔'''datas_create=[{'order_id':'157179719834','delivery_type':'EMS','delivery_number':random.randint(10000000,9999999999999999),'remarks':time.strftime("%Y-%m-%d",time.localtime(time.time()))

}]#'''创建多笔'''#datas_create = [#{'order_id': '1571298310',#'delivery_type': 'EMS',#'delivery_number': random.randint(10000000, 9999999999999999),#'remarks': '2019-11-12', },#{'order_id': '1571451612',#'delivery_type': 'EMS',#'delivery_number': random.randint(10000000, 9999999999999999),#'remarks': '2019-11-12', }#]

Waybillrquest=HttpWayBillRquest()

Token=Waybillrquest.access_token()

Create= Waybillrquest.createwaybill(datas_create,Token[0],Token[1])

测试结果为:

access_token的结果为:

{'data': {'result': 'Request is Success', 'code': '0000', 'remarks': '请求成功', 'data': {'token_type': 'Bearer', 'expires_in': 7071, 'access_token': 'b75fd73216cc1191f1acd06b0be557ffea903fa20f561'}}, 'message': 'OK', 'status': '200'}

申请运单请求头:

{'Content-Type': 'application/json; charset=UTF-8', 'Authorization': 'Bearer b75fd73216cc1191f1acd06b0be557ffea903fa20f561'}

申请运单请求参数:

[{"delivery_type": "EMS", "order_id": "1571797198304084", "remarks": "2019-11-16", "delivery_number": 2971735057491385}]

申请运单响应头:

{'Set-Cookie': 'PHPSESSID=2103irfm70b3qqbdk; path=/, PHPSESSID=2103irfm70b3qqbdk; expires=Sat, 16-Nov-2019 04:54:42 GMT; Max-Age=1440; path=/', 'Keep-Alive': 'timeout=60', 'X-Powered-By': 'PHP/5.6.40', 'Server': 'Tengine', 'Pragma': 'no-cache', 'Transfer-Encoding': 'chunked', 'Content-Encoding': 'gzip', 'Expires': 'Thu, 19 Nov 1981 08:52:00 GMT', 'Connection': 'keep-alive', 'Content-Type': 'text/html; charset=utf-8', 'Cache-Control': 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0', 'Date': 'Sat, 16 Nov 2019 04:30:42 GMT'}

申请运单响应体:

{"status":"200","message":"OK","data":{"code":"0000","result":"Request is Success","remarks":"请求成功","data":[{"order_id":"157179719834","delivery_id":"1573878642173493","error":false,"desc":""}]}}

(3)更新单条运单信息

importrandomimporttimefrom waybill.WayBill importHttpWayBillRquest

delivery_id= '1573872940367' #原始运单号

data_update1={'order_id': '15714523399','delivery_type': 'TNT','delivery_number': random.randint(10000000, 9999999999999999),'remarks':time.strftime("%Y-%m-%d",time.localtime(time.time()))

}

Waybillrquest=HttpWayBillRquest()

Token=Waybillrquest.access_token()

Update1= Waybillrquest.updatewaybill1(delivery_id, data_update1,Token[0],Token[1])

测试结果为:

ccess_token的结果为:

{'status': '200', 'message': 'OK', 'data': {'remarks': '请求成功', 'code': '0000', 'result': 'Request is Success', 'data': {'token_type': 'Bearer', 'expires_in': 6839, 'access_token': 'b75fd73216cc1191f1acd06b0be557ffea903fa20f561'}}}

更新1条运单响应头:

{'Cache-Control': 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0', 'Connection': 'keep-alive', 'Expires': 'Thu, 19 Nov 1981 08:52:00 GMT', 'Pragma': 'no-cache', 'X-Powered-By': 'PHP/5.6.40', 'Content-Encoding': 'gzip', 'Content-Type': 'text/html; charset=utf-8', 'Server': 'Tengine', 'Date': 'Sat, 16 Nov 2019 04:34:33 GMT', 'Transfer-Encoding': 'chunked', 'Set-Cookie': 'PHPSESSID=dmr786qduoqqchh; path=/, PHPSESSID=dmr786qduoqqchh; expires=Sat, 16-Nov-2019 04:58:33 GMT; Max-Age=1440; path=/', 'Keep-Alive': 'timeout=60'}

更新1条运单响应体:

{"status":"200","message":"OK","data":{"code":"0000","result":"Request is Success","remarks":"请求成功","data":{"delivery_id":"1573872940367","error":false,"desc":""}}}

(4)更新多条运单信息

importtimefrom waybill.WayBill importHttpWayBillRquest

data_update2=[

{"delivery_id": "1573461404", "delivery_type": "EMS", "delivery_number": "1573461404","remarks": time.strftime("%Y-%m-%d",time.localtime(time.time()))},

{"delivery_id": "1573461455", "delivery_type": "EMS", "delivery_number": "1573461455","remarks": time.strftime("%Y-%m-%d",time.localtime(time.time()))},

{"delivery_id": "1573461530", "delivery_type": "EMS", "delivery_number": "1573461530","remarks": time.strftime("%Y-%m-%d",time.localtime(time.time()))}

]

Waybillrquest=HttpWayBillRquest()

Token=Waybillrquest.access_token()

Update2= Waybillrquest.updatewaybill2(data_update2,Token[0],Token[1])

测试结果为:

access_token的结果为:

{'data': {'remarks': '请求成功', 'result': 'Request is Success', 'data': {'expires_in': 6634, 'access_token': 'b75fd73216cc1191f1acd06b0be557ffea903fa20f561', 'token_type': 'Bearer'}, 'code': '0000'}, 'message': 'OK', 'status': '200'}

更新多条运单响应头:

{'X-Powered-By': 'PHP/5.6.40', 'Date': 'Sat, 16 Nov 2019 04:37:58 GMT', 'Server': 'Tengine', 'Content-Encoding': 'gzip', 'Expires': 'Thu, 19 Nov 1981 08:52:00 GMT', 'Pragma': 'no-cache', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Cache-Control': 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0', 'Content-Type': 'text/html; charset=utf-8', 'Keep-Alive': 'timeout=60', 'Set-Cookie': 'PHPSESSID=754619tfmfep2lqmoh; path=/, PHPSESSID=754619tfmfep2lqmoh; expires=Sat, 16-Nov-2019 05:01:58 GMT; Max-Age=1440; path=/'}

更新多条运单响应体:

{"status":"200","message":"OK","data":{"code":"0000","result":"Request is Success","remarks":"请求成功","data":[{"delivery_id":"1573461404","error":false,"desc":""},{"delivery_id":"1573461455","error":false,"desc":""},{"delivery_id":"1573461530","error":false,"desc":""}]}}

(5)查找一条运单信息

from waybill.WayBill importHttpWayBillRquest

delivery_id= "15731193"Waybillrquest=HttpWayBillRquest()

Token=Waybillrquest.access_token()Find1= Waybillrquest.findwaybill1(delivery_id,Token[0],Token[1])

测试结果为:

access_token的结果为:

{'message': 'OK', 'status': '200', 'data': {'result': 'Request is Success', 'code': '0000', 'remarks': '请求成功', 'data': {'expires_in': 6567, 'token_type': 'Bearer', 'access_token': 'b75fd73216cc1191f1acd06b0be557'}}}

查询1条运单请求头: {'Authorization': 'Bearer b75fd73216cc1191f1acd06b0be557', 'Content-Type': 'application/json; charset=UTF-8'}

查询1条运单请求url: http://test.xapi.xborderpay.com/v3/delivery/1573119358

查询1条运单响应头:

{'Cache-Control': 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0', 'Content-Type': 'text/html; charset=utf-8', 'Server': 'Tengine', 'Connection': 'keep-alive', 'Set-Cookie': 'PHPSESSID=npmdjj39gmue5; path=/, PHPSESSID=npmdjj39gmue5; expires=Sat, 16-Nov-2019 05:03:05 GMT; Max-Age=1440; path=/', 'Pragma': 'no-cache', 'Content-Encoding': 'gzip', 'Transfer-Encoding': 'chunked', 'Date': 'Sat, 16 Nov 2019 04:39:05 GMT', 'X-Powered-By': 'PHP/5.6.40', 'Expires': 'Thu, 19 Nov 1981 08:52:00 GMT', 'Keep-Alive': 'timeout=60'}

查询1条运单响应体:

{"status":"200","message":"OK","data":{"code":"0000","result":"Request is Success","remarks":"请求成功","data":{"delivery_id":"15731193","order_id":"15731193027","date_pay":"2019-11-07 17:35:03","ship_name":"Julia Patterson","currency":"USD","amount":"66.66","delivery_type":"EMS","delivery_number":"1573119358","remarks":"2019-11-7","status":"0","is_checked":"1","is_activated":"1","by_added":"system"}}}

(6)多条件查找运单信息

from waybill.WayBill importHttpWayBillRquest

find_data={"is_checked": "1","status": "1","is_activated": "0","start_date": "2019-10-09","end_date": "2019-11-08"}

Waybillrquest=HttpWayBillRquest()

Token=Waybillrquest.access_token()

Find2= Waybillrquest.findwaybill2(find_data,Token[0],Token[1])

测试结果为:

access_token的结果为:

{'status': '200', 'message': 'OK', 'data': {'remarks': '请求成功', 'code': '0000', 'data': {'expires_in': 6377, 'token_type': 'Bearer', 'access_token': 'b75fd73216cc1191f1acd06b0be557ffea903fa20f'}, 'result': 'Request is Success'}}

多条件查询运单请求头: {'Authorization': 'Bearer b75fd73216cc1191f1acd06b0be557ffea903f', 'Content-Type': 'application/json; charset=UTF-8'}

多条件查询运单请求url: http://xxxxxx?status=1&start_date=2019-10-09&end_date=2019-11-08&is_activated=0&is_checked=1

多条件查询运单响应头: {'Content-Type': 'text/html; charset=utf-8', 'Set-Cookie': 'PHPSESSID=qle4d0m4jhtc5onr6; path=/, PHPSESSID=qle4d0m4jhtc5onr6; expires=Sat, 16-Nov-2019 05:06:15 GMT; Max-Age=1440; path=/', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'X-Powered-By': 'PHP/5.6.40', 'Pragma': 'no-cache', 'Cache-Control': 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0', 'Content-Encoding': 'gzip', 'Server': 'Tengine', 'Keep-Alive': 'timeout=60', 'Expires': 'Thu, 19 Nov 1981 08:52:00 GMT', 'Date': 'Sat, 16 Nov 2019 04:42:15 GMT'}

多条件查询运单响应体: {"status":"200","message":"OK","data":{"code":"0000","result":"Request is Success","remarks":"请求成功","data":{"total":"0","data":[]}}}

python写接口测试代码_python写运单接口测试(增改查)完整代码相关推荐

  1. python写科学计算器代码_Python编程使用tkinter模块实现计算器软件完整代码示例...

    Python编程使用tkinter模块实现计算器软件完整代码示例 来源:中文源码网    浏览: 次    日期:2018年9月2日 Python编程使用tkinter模块实现计算器软件完整代码示例 ...

  2. python tkinter计算器实例_Python编程使用tkinter模块实现计算器软件完整代码示例

    Python 提供了多个图形开发界面的库.Tkinter就是其中之一. Tkinter 模块(Tk 接口)是 Python 的标准 Tk GUI 工具包的接口 .Tk 和 Tkinter 可以在大多数 ...

  3. 用python做一个计数器_Python写一个UP主计数器(送界面定制指南)

    前言 前一段时间我在翻B站.突然,我想到了一个点子--为何不写一个UP主计数器? 于是我到翻了一下B站,发现相关视频也就几个(搜粉丝计数器的时候,一抓也有一些),翻到专栏后,居然没有一个专栏是如何写U ...

  4. django调用python脚本返回_Django框架(九)—— 单表增删改查,在Python脚本中调用Django环境...

    单表增删改查,在Python脚本中调用Django环境 一.数据库连接配置 如果连接的是pycharm默认的Sqlite,不用改动,使用默认配置即可 如果连接mysql,需要在配置文件中的settin ...

  5. Django框架(八)--单表增删改查,在Python脚本中调用Django环境

    一.数据库连接配置 如果连接的是pycharm默认的Sqlite,不用改动,使用默认配置即可 如果连接mysql,需要在配置文件中的setting中进行配置: 将DATABASES={} 更新为 DA ...

  6. 数据结构上机-尾、头插法建立单链表-单链表遍历C语言完整代码实现

    点击此处跳转视频链接:数据结构上机-尾.头插法建立单链表-单链表遍历C语言完整代码实现

  7. mybatis --入门 单表增删改查-curd

    目录 1. mybatis 环境搭建 2. 实体类映射文件配置(写sql) 3. mybatis核心配置文件 (环境配置) 4. 测试 mybatis document https://mybatis ...

  8. mysql如何修改学生表_MySQL 详细单表增删改查crud语句

    MySQL 增删改查语句 1.创建练习表 这里练习表没有满足三范式 第一范式(又称 1NF):保证每列的原子性 数据表中的每一列(字段),必须是不可拆分的最小单元,也就是确保每一列的原子性.满足第一范 ...

  9. SpringBoot+MyBatisPlus+Vue 前后端分离项目快速搭建【后端篇】【快速生成后端代码、封装结果集、增删改查、模糊查找】【毕设基础框架】

    前后端分离项目快速搭建[后端篇] 数据库准备 后端搭建 1.快速创建个SpringBoot项目 2.引入依赖 3.编写代码快速生成代码 4.运行代码生成器生成代码 5.编写application.pr ...

最新文章

  1. 【翻译】A Next-Generation Smart Contract and Decentralized Application Platform
  2. HttpClient 如何设置请求接口等待时间
  3. uPC1677射频信号放大芯片
  4. WIN7的MKLINK命令,创建文件(夹)连接(链接)
  5. ASP.NET页面的处理过程完全版_AX
  6. NgModule imports定义的运行时数据结构
  7. 产品认知:说说产品经理的底层思维——用户思维
  8. mysql sqlexception_c-很奇怪-mysql的sql :: SQLException未被其类型捕...
  9. linux中如何快速进入某个目录
  10. git为私有仓库设置密码_真香!在局域网下行云流水般使用git
  11. 刷新按钮_处理数据透视表的隐藏选项(四):固定报表刷新前后的列宽和格式...
  12. python rindex()_Python3 rindex()方法
  13. 京东也准备向社区团购进发了?
  14. 在SQL数据库中搜索对象的不同方法
  15. 游戏中用户升级的设计
  16. 【实习面经】头条后台开发岗一面凉经
  17. python f{} 字符串用法详解(含冒号用法)
  18. arcgis javascript Measurement的使用
  19. 通用文件清除脚本,可对多个指定目录按照磁盘空间、文件保存天数进行清理,并可设置目录扫描深度
  20. ORACLE:分组函数

热门文章

  1. openshift学习_在OpenShift上将JMS与JBoss A-MQ结合使用。 学习了有关远程客户端和加密的经验。...
  2. osgi架构与linux_OSGi:进入微服务架构的门户
  3. spring 2.2 改进_Spring 4中@ControllerAdvice的改进
  4. js实现日历框上一日下一日_一日三项令人兴奋的Lucene功能
  5. ejb 2.1 jboss_JBoss AS 8中的Java EE 7和EJB 3.2支持
  6. 在5分钟内将Spring Boot作为Windows服务启动
  7. 什么是JAX-RS注释? (第3部分)
  8. jax-rs jax-ws_通过JAX-WS Provider在Web服务中利用MOXy
  9. java面试题:集合_Java:选择正确的集合
  10. junit:junit_JUnit和Hamcrest:在assertEquals上进行改进