requests代码:
import requests,pytest,allure
from readData import readExcel
@allure.feature("移动设备云平台")
class Test_yunTerrace():
lst = readExcel("message", 1, 20)
@allure.story("通知消息数统计")
@pytest.mark.parametrize("agencyId,colFlag,result",lst)
def test_massage(self,agencyId,colFlag,result):
url = "http://192.168.1.201:8888/1/statistic/getMsgSum"
params = "access_token=23421422&agencyId="+agencyId+"&colFlag="+colFlag
req = requests.get(url,params) #发送get请求
print(req.status_code,colFlag) #获取响应状态码
print(type(req.text))
print(type(eval(req.text)))
#assert eval(req.text)["msg"] == result
# try:
# assert eval(req.text)["msg"]==result
# except:
# print("用例不通过")
#print(type(eval(req.text))) #eval用来执行一个字符串表达式,并返回表达式的值。
lst = readExcel("agency", 1, 10)
@allure.story("新建代理")
@pytest.mark.parametrize("agencyId,name,cotact,phone,result", lst)
def test_newAgency(self,agencyId,name,cotact,phone,result):
url1 = "http://192.168.1.201:8888/1/agency/createAgency"
json = {
"access_token":"XXXXX",
"agencyId":agencyId,
"userId":5453,
"name" : name,
"contact":cotact,
"phone":phone,
"email":"test@163.com",
"province":"32",
"city":"32",
"area":"46",
"address":"莲花西街道",
"describe" :"参数测试"
}
reqp = requests.post(url1,json=json) #发送post请求
print(reqp.text)
assert eval(reqp.text)["msg"] == result
def test_registeredVisitorInformation(self, ValidEndTime, IsStaff):
urls = "http://dm.oa.tencent.com/api/device/RegistGuest"
json = {
"GuestID": "rtx",
"VerifyCode": "Mac地址",
"ValidEndTime": 8*60*60,
"IsStaff": 1,
}
reqp = requests.post(urls, json=json) # 发送post请求
print(reqp.text)
assert eval(reqp.text)["Ret"] == 0
xlrd数据分离:
import xlrd #xlrd版本1.x,2.0以上版本不识别xlsx,只识别xls
def readExcel(sheet,statRow,endRow):
xls = xlrd.open_workbook(r"dataFile\data.xlsx") #打开Excel文件
sht = xls.sheet_by_name(sheet) #选择sheet页
row=sht.nrows #获取总行数
col=sht.ncols #获取总列数
lsts = []
for r in range(statRow-1,endRow):
if col > 1:
lst = []
for c in range(0,col):
s = sht.cell_value(r,c)
if type(s)==float: #python读取Excel的数字是浮点型,要做类型处理
s = int(s)
lst.append(s)
lsts.append(lst)
return lsts
if __name__ == '__main__':
#lst = readExcel("message", 1, 20)
lst = readExcel("agency", 1, 10)
print(lst)
message测试数据
1 | 1 | Success | 1 | 2 | Success | 1 | 3 | Success | 1 | 4 | Success | 1 | 5 | Success | 1 | 6 | Success | 1 | 7 | Success | 1 | 8 | Success | 1 | 9 | Success | 1 | 10 | Success | 1 | 11 | Success | 1 | 12 | Success | 1 | 13 | Success | 1 | 14 | Success | 1 | 15 | Success | 1 | 16 | 未找到指定信息 | | 1 | 请提交代理商ID | 1 | | 获取统计信息类别 | 2 | 4 | 权限不足 | 2 | 8 | 权限不足 |
agency测试数据:
1 | 广东移动 | 三三 | 13345679874 | Success | 1 | 广东移动1 | 四四 | 13345679874 | Success | 1 | 广东移动a | 五五 | 13345679874 | Success | 1 | 广东移动! | 六六 | 13345679874 | Success | 1 | 广东移动 | 七七 | 13345679874 | Success | 2 | 广东移动 | 三三 | 13345679874 | Success | 2 | 广东移动 | 三三 | 13345679874 | Success | 2 | 广东移动 | 三三 | 13345679874 | Success | 2 | 广东移动 | 三三 | 13345679874 | Success | 2 | 广东移动 | 三三 | 13345679874 | Success |
|