Files
jiekou-python3/testCase/case.py

87 lines
3.5 KiB
Python
Raw Permalink 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
2023-02-19 18:16:03 +08:00
from public.get_excel import datacel
from public.log import LOG, logger
2018-03-29 13:09:26 +08:00
import os
from config.config import Config_Try_Num, TestPlanUrl
2020-05-09 21:24:18 +08:00
path = os.path.join(os.path.join(os.getcwd(), 'test_case_data'), 'case.xlsx')
2022-01-15 13:44:42 +08:00
2018-09-03 21:27:29 +08:00
listid, listkey, listconeent, listurl, listfangshi, listqiwang, listname = datacel(path)
2023-02-19 18:16:03 +08:00
from public.panduan import assert_in
2020-05-09 21:24:18 +08:00
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
2020-05-09 21:24:18 +08:00
error_num = 0
2017-08-01 21:39:11 +08:00
for i in range(len(listurl)):
2020-05-09 21:24:18 +08:00
while error_num <= Config_Try_Num + 1:
parem = {'key': listkey[i]}
parem.update({'info': eval(listconeent[i])})
#parem=eval(data_test[listconeent[i])
api = TestApi(url=TestPlanUrl + listurl[i], parame=parem, method=listfangshi[i])
2018-09-04 12:59:11 +08:00
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]))
2023-01-16 11:35:20 +08:00
assert_re = assert_in(asserassert=listqiwang[i], returnjson=apijson)
2018-09-03 21:27:29 +08:00
if assert_re['code'] == 0:
list_json.append(apijson['result'])
listrelust.append('pass')
list_pass += 1
2020-05-09 21:24:18 +08:00
error_num = 0
2018-09-04 12:59:11 +08:00
continue
2018-09-03 21:27:29 +08:00
elif assert_re['code'] == 1:
2020-05-09 21:24:18 +08:00
if error_num <= Config_Try_Num:
error_num += 1
2018-09-04 12:59:11 +08:00
LOG.info('失败重试中')
else:
LOG.info('失败重试中次数用完,最后结果')
2020-05-09 21:24:18 +08:00
error_num = 0
2018-09-04 12:59:11 +08:00
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:
2020-05-09 21:24:18 +08:00
if error_num < Config_Try_Num:
error_num += 1
2018-09-04 12:59:11 +08:00
LOG.info('失败重试中')
else:
LOG.info('失败重试中次数用完,最后结果')
2020-05-09 21:24:18 +08:00
error_num = 0
2018-09-04 12:59:11 +08:00
list_exption += 1
listrelust.append('exception')
list_json.append(assert_re['result'])
break
2018-09-03 21:27:29 +08:00
else:
2020-05-09 21:24:18 +08:00
if error_num < Config_Try_Num:
error_num += 1
2018-09-04 12:59:11 +08:00
LOG.info('失败重试中')
else:
LOG.info('失败重试中次数用完,最后结果')
2020-05-09 21:24:18 +08:00
error_num = 0
2018-09-04 12:59:11 +08:00
list_weizhi += 1
listrelust.append('未知错误')
list_json.append('未知错误')
break
else:
2020-05-09 21:24:18 +08:00
if error_num < Config_Try_Num:
error_num += 1
2018-09-04 12:59:11 +08:00
LOG.info('失败重试中')
else:
LOG.info('失败重试中次数用完,最后结果')
2020-05-09 21:24:18 +08:00
error_num = 0
2018-09-04 12:59:11 +08:00
list_exption += 1
listrelust.append('exception')
list_json.append(apijson['result'])
break
2020-05-09 21:24:18 +08:00
return listrelust, list_fail, list_pass, list_json, list_exption, list_weizhi