首页 > 编程语言 > 详细

简单使用 Requests+Python2 接口测试 读取 Excel 完成接口测试

时间:2018-08-24 14:35:22      阅读:254      评论:0      收藏:0      [点我收藏+]

代码块

 

import xlrd
import unittest
import requests,json

class Test(unittest.TestCase):
def duqu(self, filename=r‘E:\test\project\test_case\test.xlsx‘): # 读取 Excel文件
data = xlrd.open_workbook(filename) # 打开文件把参数传给 data
table = data.sheets()[0] # 通过索引顺序获取Excel 文件
parameter = table.row_values(1) # 获取整行数据 获取Excel 第二行数据
jsoninfo = eval(parameter[3]) # 因为 parameter 变量类型是str 需要用eval函数转换成dict
url = ‘http://基础url地址‘ + parameter[2] # 基础地址 加上测试接口测路径
return url,parameter[1], jsoninfo

def test_requests(self):
auth = self.duqu() # 调用 duqu 函数
head = {
"platform": "ios",
"xnServer": "aio-app-server",
"version": "1.0.0",
"Content-Type": "application/json"
}
# requests库作为接口核心,传入url,post请求,json参数
res = requests.request("%s" % auth[1], auth[0], json=auth[2],headers=head)
self.assertEqual(res.status_code, 200) # 断言code 是否等于200
self.assertNotIn(res.text, ‘"ret":0‘)



if __name__==‘__main__‘:
unittest.main()



test.xlsx

技术分享图片

 

简单使用 Requests+Python2 接口测试 读取 Excel 完成接口测试

原文:https://www.cnblogs.com/txx403341512/p/9529556.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!