zoukankan      html  css  js  c++  java
  • 简单使用 Requests+Python2 接口测试 读取 Excel 完成接口测试

    代码块

    import xlrd
    import unittest
    import requests,json

    class Test(unittest.TestCase):
    def duqu(self, filename=r'E: estproject est_case est.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

  • 相关阅读:
    HDU 1224 无环有向最长路
    HDU 1220 简单数学题
    HDU 1203 背包问题
    HDU 1176 DP
    HDU 1159 LCS最长公共子序列
    HDU 1160 排序或者通过最短路两种方法解决
    hdu 2349 最小生成树
    次小生成树的学习
    最小生成树prime算法模板
    poj 1679 判断最小生成树是否唯一
  • 原文地址:https://www.cnblogs.com/txx403341512/p/9529556.html
Copyright © 2011-2022 走看看