Files
jiekou-python3/testCase/case.py

79 lines
3.3 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
# @Time : 2017/6/4 20:15
# @Author : lileilei
2017-11-01 10:28:31 +08:00
# @File : case.py
2018-04-12 14:24:53 +08:00
from Interface.testFengzhuang import TestApi
2018-09-03 21:27:29 +08:00
from Public.get_excel import datacel
from Public.log import LOG, logger
2018-03-29 13:09:26 +08:00
import os
2018-09-04 12:59:11 +08:00
from config.config_T import Config_Try_Num,TestPlanUrl
2018-09-03 21:27:29 +08:00
path = os.getcwd() + '\\test_case_data\\case.xlsx'
listid, listkey, listconeent, listurl, listfangshi, listqiwang, listname = datacel(path)
2017-08-03 13:03:33 +08:00
from Public.panduan import assert_in
2017-10-16 21:00:09 +08:00
@logger('测试')
2017-08-01 21:39:11 +08:00
def testinterface():
list_pass = 0
list_fail = 0
list_json = []
2018-09-03 21:27:29 +08:00
listrelust = []
list_weizhi = 0
list_exption = 0
2018-09-04 12:59:11 +08:00
error_num=0
2017-08-01 21:39:11 +08:00
for i in range(len(listurl)):
2018-09-04 12:59:11 +08:00
while error_num<=Config_Try_Num+1:
api = TestApi(url=TestPlanUrl+listurl[i], key=listkey[i], connent=listconeent[i], fangshi=listfangshi[i])
apijson = api.getJson()
2018-09-03 21:27:29 +08:00
if apijson['code'] == 0:
LOG.info('inputdata> 参数:%s, url:%s ,返回:%s,预期:%s' % (listconeent[i], listurl[i], apijson, listqiwang[i]))
assert_re = assert_in(asserqiwang=listqiwang[i], fanhuijson=apijson)
if assert_re['code'] == 0:
list_json.append(apijson['result'])
listrelust.append('pass')
list_pass += 1
2018-09-04 12:59:11 +08:00
error_num=0
continue
2018-09-03 21:27:29 +08:00
elif assert_re['code'] == 1:
2018-09-04 12:59:11 +08:00
if error_num <=Config_Try_Num:
error_num+=1
LOG.info('失败重试中')
else:
LOG.info('失败重试中次数用完,最后结果')
error_num=0
list_fail += 1
listrelust.append('fail')
list_json.append(apijson['result'])
break
2018-09-03 21:27:29 +08:00
elif assert_re['code'] == 2:
2018-09-04 12:59:11 +08:00
if error_num <Config_Try_Num:
error_num+=1
LOG.info('失败重试中')
else:
LOG.info('失败重试中次数用完,最后结果')
error_num=0
list_exption += 1
listrelust.append('exception')
list_json.append(assert_re['result'])
break
2018-09-03 21:27:29 +08:00
else:
2018-09-04 12:59:11 +08:00
if error_num <Config_Try_Num:
error_num+=1
LOG.info('失败重试中')
else:
LOG.info('失败重试中次数用完,最后结果')
error_num=0
list_weizhi += 1
listrelust.append('未知错误')
list_json.append('未知错误')
break
else:
2018-09-04 12:59:11 +08:00
if error_num <Config_Try_Num:
error_num+=1
LOG.info('失败重试中')
else:
LOG.info('失败重试中次数用完,最后结果')
error_num=0
list_exption += 1
listrelust.append('exception')
list_json.append(apijson['result'])
break
return listrelust, list_fail, list_pass, list_json, list_exption, list_weizhi