自动测试接口各key内容的返回结果
2017-11-03 08:52
267 查看
自动化测试各个json中各个key内容错误和为空时的返回结果。
# -*- coding:utf-8 -*- import requests import json import time import base64 import warnings warnings.filterwarnings("ignore") ''' 放置两个一样原始内容的产品1json的文件yc.lic和yc1.lic在脚本目录 放置两个一样原始内容的产品2json文件fcg.lic和fcg1.lic在脚本目录 修改测试的base_url ''' def licens1(file): #产品1地址改这个 base_url = "https://XX" url = base_url+"XXX" data1 = requests.get(url,verify=False) data1 = data1.text token = json.loads(data1) token = token['data']['token'] #print token data = {'token':token} files = { #2.lic是base64加密的文件 "licenseFile": open(file,"rb") } url2 = base_url + "XX" r = requests.post(url2,data=data,files=files,verify=False) print r.text def licens2(file): #产品2地址改这个地址 base_url = "XX" url = base_url+"XX" post_data={"Content-Type":"application/x-www-form-urlencoded"} data1 = requests.post(url,data=post_data,verify=False) token = data1.text #print token data = {'token':token} files = { #2.lic是base64加密的文件 "licenseFile": open("2.lic","rb") } url2 = base_url + "XX"+token #print url2 r = requests.post(url2,data=data,files=files,verify=False) print r.text def autoread(license,filename1,filename2): cases = ['','test'] for case in cases: with open(filename1,"rb") as f: line = f.readline() d = json.loads(line) for key,value in d.items(): #print type(value) if type(value) == dict: for key1, value1 in value.items(): #print (key1, 'value:',value1) #value[key1] = case with open(filename2,"rb") as ff: line = ff.readline() dd = json.loads(line) dd[key][key1] = case with open("2.lic","wb") as f2: f2.write(base64.b64encode(json.dumps(dd))) if case =="": print u"%s为空的时返回结果:"%key1, else: print u"%s错误时返回结果:"%key1, #print json.dumps(dd) f2.close() if license==1: licens1("2.lic") else: licens2("2.lic") else: #print (key, 'value:',value) with open(filename2,"rb") as ff: line = ff.readline() dd = json.loads(line) dd[key] = case with open("2.lic","wb") as f2: f2.write(base64.b64encode(json.dumps(dd))) if case =="": print u"%s为空的时返回结果:"%key, else: print u"%s错误时返回结果:"%key, #print json.dumps(dd) f2.close() if license==1: licens1("2.lic") else: licens2("2.lic") if __name__ == '__main__': print "******************产品1自动测试结果*******************************" autoread(1,"yc.lic","yc1.lic") print "******************产品2自动测试结果*******************************" autoread(2,"fcg.lic","fcg1.lic")
相关文章推荐
- 使用jmeter做接口测试,怎么验证、核对响应结果中json的内容?
- 利用ajax在index页面自动执行方法并显示相关内容,在执行相关按钮操作(如登录注册)后返回index页面后ajax不执行,无法显示相关内容的问题解决方法之一
- 请求接口返回内容
- ab压力测试,解释返回结果的含义
- RestFul接口调试中常见返回结果汇总
- Common Subsequence 动态规划 不难 但是犯了个错误刚开始 没用标记数组 直接使用a判断 是否为零 结果是测试数据有很多key为零 超时
- POST数据到指定url并返回结果页面内容
- apache ab工具页面压力测试返回结果含义解释
- [图解教程]Eclipse不可不知的用法之二:自动生成接口和JUnit测试类
- php curl获取https页面内容, 不直接输出返回结果的设置
- weiapi2.2 HelpPage自动生成接口说明文档和接口测试功能
- GPIB接口的自动测试系统
- SQL存储过程测试(7)——当待测存储过程返回out参数时 如何判断测试结果是否通过
- salesforce零基础学习(八十)使用autoComplete 输入内容自动联想结果以及去重实现
- 【接口测试】接口测试内容简介
- FFmpeg接口 编写视频转码测试程序结果
- IdentityHashMap类:增加相同Key(键)内容的结果
- 返回结果自动在标签外添加<tr><td class="tdlabel">........</td></tr>
- RestFul接口调试返回对应编码结果