2022-04-23 13:10:50 +08:00
|
|
|
|
import ddt, unittest, os, yaml
|
2020-05-09 21:24:18 +08:00
|
|
|
|
from Interface.testFengzhuang import TestApi
|
2023-02-19 18:16:03 +08:00
|
|
|
|
from public.get_excel import makedata
|
|
|
|
|
|
from public.log import LOG
|
|
|
|
|
|
from public.panduan import assertre
|
2022-04-23 13:10:50 +08:00
|
|
|
|
from config.config import TestPlanUrl
|
2022-01-16 11:07:30 +08:00
|
|
|
|
|
|
|
|
|
|
file_dir = os.path.join(os.getcwd(), 'test_Report')
|
|
|
|
|
|
file_reslut = os.path.join(file_dir, 'caseresult.yaml')
|
2020-05-09 21:24:18 +08:00
|
|
|
|
|
|
|
|
|
|
data_test = makedata()
|
|
|
|
|
|
|
2022-04-23 13:10:50 +08:00
|
|
|
|
|
2022-01-16 11:07:30 +08:00
|
|
|
|
def write(data):
|
|
|
|
|
|
with open(file_reslut, 'a', encoding='utf-8') as f:
|
|
|
|
|
|
yaml.dump(data, f, allow_unicode=True)
|
2022-04-23 13:10:50 +08:00
|
|
|
|
|
|
|
|
|
|
|
2022-01-16 11:07:30 +08:00
|
|
|
|
def read(data):
|
|
|
|
|
|
f = open(file_reslut, 'r', encoding='utf-8')
|
|
|
|
|
|
d = yaml.load(f, Loader=yaml.FullLoader)
|
|
|
|
|
|
return d[data]
|
|
|
|
|
|
|
2020-05-09 21:24:18 +08:00
|
|
|
|
|
2020-05-08 18:29:34 +08:00
|
|
|
|
@ddt.ddt
|
|
|
|
|
|
class MyTest(unittest.TestCase):
|
|
|
|
|
|
def setUp(self):
|
|
|
|
|
|
LOG.info('测试用例开始执行')
|
2020-05-09 21:24:18 +08:00
|
|
|
|
|
2020-05-08 18:29:34 +08:00
|
|
|
|
def tearDown(self):
|
|
|
|
|
|
LOG.info('测试用例执行完毕')
|
2020-05-09 21:24:18 +08:00
|
|
|
|
|
2020-05-08 18:29:34 +08:00
|
|
|
|
@ddt.data(*data_test)
|
2020-05-09 21:24:18 +08:00
|
|
|
|
def test_api(self, data_test):
|
2022-01-16 11:07:30 +08:00
|
|
|
|
'''
|
|
|
|
|
|
1.处理参数
|
|
|
|
|
|
2.判断参数是否有依赖
|
|
|
|
|
|
3.依赖用例参数从本地获取
|
|
|
|
|
|
4.获取失败,用例失败
|
|
|
|
|
|
5.拼接后请求
|
|
|
|
|
|
'''
|
|
|
|
|
|
parem = {'key': data_test['key']}
|
|
|
|
|
|
try:
|
2022-04-23 13:10:50 +08:00
|
|
|
|
parem_dict = eval(data_test['coneent'])
|
|
|
|
|
|
for key, value in parem_dict.items():
|
2022-01-16 11:07:30 +08:00
|
|
|
|
if str(value).startswith("&"):
|
|
|
|
|
|
try:
|
2022-04-23 13:10:50 +08:00
|
|
|
|
reply_key_id = str(value).split("&")[-1].split("=")
|
|
|
|
|
|
reply_keyid = reply_key_id[0]
|
|
|
|
|
|
reply_key_key = reply_key_id[1]
|
|
|
|
|
|
reslut = read(reply_keyid)
|
2022-01-16 11:07:30 +08:00
|
|
|
|
if reslut is None:
|
2022-04-23 13:10:50 +08:00
|
|
|
|
self.assertTrue(False, '依赖用例获取失败')
|
|
|
|
|
|
get_value = reslut[reply_key_key]
|
2022-01-16 11:07:30 +08:00
|
|
|
|
if get_value is None:
|
|
|
|
|
|
self.assertTrue(False, '依赖参数获取失败,不存在')
|
2022-04-23 13:10:50 +08:00
|
|
|
|
parem_dict[key] = get_value
|
2022-01-16 11:07:30 +08:00
|
|
|
|
except Exception as e:
|
2022-04-23 13:10:50 +08:00
|
|
|
|
LOG.info("用例依赖执行失败:" + str(e))
|
|
|
|
|
|
self.assertTrue(False, '用例依赖执行失败')
|
2022-01-16 11:07:30 +08:00
|
|
|
|
|
2022-04-23 13:10:50 +08:00
|
|
|
|
parem.update({'info': parem_dict})
|
2022-01-16 11:07:30 +08:00
|
|
|
|
except:
|
2022-04-23 13:10:50 +08:00
|
|
|
|
self.assertTrue(False, msg="参数格式不对")
|
2023-02-19 18:16:03 +08:00
|
|
|
|
LOG.info(parem)
|
2022-04-23 13:10:50 +08:00
|
|
|
|
api = TestApi(url=TestPlanUrl + data_test['url'],
|
2022-01-16 11:07:30 +08:00
|
|
|
|
parame=parem,
|
2023-02-19 18:16:03 +08:00
|
|
|
|
method=data_test['method'])
|
|
|
|
|
|
LOG.info('输入参数:url:%s,key:%s,参数:%s,请求方式:%s' % (data_test['url'], data_test['key'], data_test['assertconnect'],
|
2020-05-09 21:24:18 +08:00
|
|
|
|
LOG.info('输入参数:url:%s,key:%s,参数:%s,请求方式:%s' % (
|
2023-02-19 18:16:03 +08:00
|
|
|
|
data_test['url'], data_test['key'], data_test['assertconnect'],
|
|
|
|
|
|
data_test['method']))))
|
2020-05-08 18:29:34 +08:00
|
|
|
|
apijson = api.getJson()
|
2022-04-23 13:10:50 +08:00
|
|
|
|
reslut = {}
|
|
|
|
|
|
reslut[data_test['id']] = apijson
|
2022-01-16 11:07:30 +08:00
|
|
|
|
write(reslut)
|
2020-05-09 21:24:18 +08:00
|
|
|
|
LOG.info('返回结果:%s' % apijson)
|
2023-02-19 18:16:03 +08:00
|
|
|
|
assertall = assertre(asserassert=data_test['assertconnect'])
|
2022-01-15 14:38:32 +08:00
|
|
|
|
self.assertNotEqual(dict(assertall), dict(apijson), msg='预期和返回不一致')
|