mirror of https://gitee.com/a529548204/apitest.git
不记得优化了啥了 更新下
This commit is contained in:
parent
e10a6381bd
commit
4f6cdf493d
|
@ -3,6 +3,7 @@ import json
|
|||
import logging
|
||||
import os
|
||||
import random
|
||||
import time
|
||||
|
||||
import allure
|
||||
import requests
|
||||
|
@ -30,7 +31,7 @@ class apiSend(object):
|
|||
dataran = replace_random(data)
|
||||
return dataran
|
||||
|
||||
def post(self, address, header, request_parameter_type="json", timeout=8, data=None, files=None,host="host"):
|
||||
def post(self, address, header, request_parameter_type="json", timeout=8, data=None, files=None, host="host"):
|
||||
"""
|
||||
post请求
|
||||
:param host:
|
||||
|
@ -43,16 +44,17 @@ class apiSend(object):
|
|||
:return:
|
||||
"""
|
||||
|
||||
url = str(self.http_type) + "://" + host_manage(hos='${{{}}}$'.format(host)) + address
|
||||
iniaddress = replace_random(address, param=data["urlparam"])
|
||||
url = str(self.http_type) + "://" + host_manage(hos='${{{}}}$'.format(host)) + iniaddress
|
||||
data_random = self.iniDatas(data["param"])
|
||||
logging.info("请求地址:%s" % "" + url)
|
||||
logging.info("请求地址:%s" % "" + str(address))
|
||||
logging.info("请求头: %s" % str(header))
|
||||
|
||||
logging.info("请求参数: %s" % str(data_random))
|
||||
if 'form-data' in request_parameter_type:
|
||||
with allure.step("POST上传文件"):
|
||||
allure.attach(name="请求地址", body=url)
|
||||
allure.attach(name="请求头", body=str(header))
|
||||
allure.attach(name="请求参数", body=str(data))
|
||||
allure.attach(name="请求参数", body=str(data_random))
|
||||
if files is not None:
|
||||
for i in files:
|
||||
value = files[i]
|
||||
|
@ -78,7 +80,7 @@ class apiSend(object):
|
|||
response = requests.post(url=url, data=multipart, headers={'Content-Type': multipart.content_type},
|
||||
timeout=timeout)
|
||||
else:
|
||||
data_random = self.iniDatas(data)
|
||||
|
||||
with allure.step("POST请求接口"):
|
||||
allure.attach(name="请求地址", body=url)
|
||||
allure.attach(name="请求头", body=str(header))
|
||||
|
@ -100,7 +102,7 @@ class apiSend(object):
|
|||
logging.error(e)
|
||||
raise
|
||||
|
||||
def get(self, address, header, data, timeout=8,host="host"):
|
||||
def get(self, address, header, data, timeout=8, host="host"):
|
||||
"""
|
||||
get请求
|
||||
:param host:
|
||||
|
@ -110,8 +112,12 @@ class apiSend(object):
|
|||
:param timeout: 超时时间
|
||||
:return:
|
||||
"""
|
||||
data_random = self.iniDatas(data)
|
||||
url = str(self.http_type) + "://" + host_manage(hos='${{{}}}$'.format(host)) + address
|
||||
iniaddress = replace_random(address, param=data["urlparam"])
|
||||
# if isinstance(data, dict):
|
||||
# if "urlparam" in data.keys():
|
||||
# address = replace_random(address, param=data["urlparam"])
|
||||
data_random = self.iniDatas(data["param"])
|
||||
url = str(self.http_type) + "://" + host_manage(hos='${{{}}}$'.format(host)) + iniaddress
|
||||
logging.info("请求地址:%s" % "" + url)
|
||||
logging.info("请求头: %s" % str(header))
|
||||
logging.info("请求参数: %s" % str(data_random))
|
||||
|
@ -135,7 +141,7 @@ class apiSend(object):
|
|||
logging.error(e)
|
||||
raise
|
||||
|
||||
def put(self, address, header, request_parameter_type="json", timeout=8, data=None, files=None,host="host"):
|
||||
def put(self, address, header, request_parameter_type="json", timeout=8, data=None, files=None, host="host"):
|
||||
"""
|
||||
put请求
|
||||
:param host:
|
||||
|
@ -147,21 +153,22 @@ class apiSend(object):
|
|||
:param files: 文件路径
|
||||
:return:
|
||||
"""
|
||||
|
||||
url = str(self.http_type) + "://" + host_manage(hos='${{{}}}$'.format(host)) + address
|
||||
iniaddress = replace_random(address, param=data["urlparam"])
|
||||
url = str(self.http_type) + "://" + host_manage(hos='${{{}}}$'.format(host)) + iniaddress
|
||||
logging.info("请求地址:%s" % "" + url)
|
||||
logging.info("请求头: %s" % str(header))
|
||||
|
||||
if request_parameter_type == 'raw':
|
||||
data_random = self.iniDatas(data["param"])
|
||||
else:
|
||||
data_random = data
|
||||
logging.info("请求参数: %s" % str(data_random))
|
||||
with allure.step("PUT请求接口"):
|
||||
allure.attach(name="请求地址", body=url)
|
||||
allure.attach(name="请求头", body=str(header))
|
||||
allure.attach(name="请求参数", body=str(data))
|
||||
allure.attach(name="请求参数", body=str(data_random))
|
||||
|
||||
if request_parameter_type == 'raw':
|
||||
data = self.iniDatas(data)
|
||||
else:
|
||||
data = data
|
||||
response = requests.put(url=url, data=data, headers=header, timeout=timeout, files=files)
|
||||
response = requests.put(url=url, data=data_random, headers=header, timeout=timeout, files=files)
|
||||
try:
|
||||
logging.info("请求接口结果: %s" % str(response.json()))
|
||||
return response.json(), response.elapsed.total_seconds()
|
||||
|
@ -174,7 +181,7 @@ class apiSend(object):
|
|||
logging.error(e)
|
||||
raise
|
||||
|
||||
def delete(self, address, header, data, timeout=8,host="host"):
|
||||
def delete(self, address, header, data, timeout=8, host="host"):
|
||||
"""
|
||||
get请求
|
||||
:param host:
|
||||
|
@ -184,11 +191,12 @@ class apiSend(object):
|
|||
:param timeout: 超时时间
|
||||
:return:
|
||||
"""
|
||||
data_random = self.iniDatas(data)
|
||||
url = str(self.http_type) + "://" + host_manage(hos='${{{}}}$'.format(host)) + address
|
||||
iniaddress = replace_random(address, param=data["urlparam"])
|
||||
data_random = self.iniDatas(data["param"])
|
||||
url = str(self.http_type) + "://" + host_manage(hos='${{{}}}$'.format(host)) + iniaddress
|
||||
logging.info("请求地址:%s" % "" + url)
|
||||
logging.info("请求头: %s" % str(header))
|
||||
|
||||
logging.info("请求参数: %s" % str(data_random))
|
||||
with allure.step("DELETE请求接口"):
|
||||
allure.attach(name="请求地址", body=url)
|
||||
allure.attach(name="请求头", body=str(header))
|
||||
|
@ -225,6 +233,7 @@ class apiSend(object):
|
|||
|
||||
apisend = apiSend()
|
||||
if __name__ == '__main__':
|
||||
apisend("/123123","get",data="er",headers={
|
||||
"Content-Type": "application/json"
|
||||
},host="host2")
|
||||
ress = apisend("/$url(home_id)$", "get", data={"param":None,"urlparam": {"home_id": 123}}, headers={
|
||||
"Content-Type": "application/json"
|
||||
}, host="host")
|
||||
print(ress)
|
||||
|
|
|
@ -90,7 +90,7 @@ def assert_text(hope_res, real_res,third_data=None,third_datas=None):
|
|||
allure.attach(name="期望结果", body=str(h_res))
|
||||
allure.attach(name='实际实际结果', body=str(r_res))
|
||||
assert str(r_res) == str(h_res["value"])
|
||||
logging.info("json断言通过, 期望结果{0}, 实际结果{1}".format(h_res, r_res))
|
||||
logging.info("json断言通过, 期望结果'{0}', 实际结果'{1}'".format(h_res, r_res))
|
||||
elif third_datas:
|
||||
if h_res["relevance"]:
|
||||
h_res["value"] = replace_random(str(h_res["value"]), res=third_datas[h_res["relevance"]])
|
||||
|
@ -98,9 +98,9 @@ def assert_text(hope_res, real_res,third_data=None,third_datas=None):
|
|||
allure.attach(name="期望结果", body=str(h_res))
|
||||
allure.attach(name='实际实际结果', body=str(r_res))
|
||||
assert str(r_res) == str(h_res["value"])
|
||||
logging.info("json断言通过, 期望结果{0}, 实际结果{1}".format(h_res, r_res))
|
||||
logging.info("json断言通过, 期望结果'{0}', 实际结果'{1}'".format(h_res, r_res))
|
||||
except AssertionError:
|
||||
logging.error("json断言未通过, 期望结果{0}, 实际结果{1}".format(h_res, r_res))
|
||||
logging.error("json断言未通过, 期望结果'{0}', 实际结果'{1}'".format(h_res, r_res))
|
||||
raise
|
||||
elif h_res["asserttype"] == "!=":
|
||||
try:
|
||||
|
@ -109,9 +109,9 @@ def assert_text(hope_res, real_res,third_data=None,third_datas=None):
|
|||
allure.attach(name="json期望结果", body=str(h_res))
|
||||
allure.attach(name='json实际实际结果', body=str(r_res))
|
||||
assert str(r_res) != str(h_res["value"])
|
||||
logging.info("json断言通过, 期望结果{0}, 实际结果{1}".format(h_res, r_res))
|
||||
logging.info("json断言通过, 期望结果'{0}', 实际结果'{1}'".format(h_res, r_res))
|
||||
except AssertionError:
|
||||
logging.error("json断言未通过, 期望结果{0}, 实际结果{1}".format(h_res, r_res))
|
||||
logging.error("json断言未通过, 期望结果'{0}', 实际结果'{1}'".format(h_res, r_res))
|
||||
raise
|
||||
elif h_res["asserttype"] == "in":
|
||||
r_res = str(r_res)
|
||||
|
@ -121,9 +121,9 @@ def assert_text(hope_res, real_res,third_data=None,third_datas=None):
|
|||
allure.attach(name="期望结果", body=str(h_res))
|
||||
allure.attach(name='实际实际结果', body=str(r_res))
|
||||
assert str(r_res) in str(h_res["value"])
|
||||
logging.info("json断言通过, 期望结果{0}, 实际结果{1}".format(h_res, real_res))
|
||||
logging.info("json断言通过, 期望结果'{0}', 实际结果'{1}'".format(h_res, real_res))
|
||||
except AssertionError:
|
||||
logging.error("json断言未通过, 期望结果{0}, 实际结果{1}".format(h_res, real_res))
|
||||
logging.error("json断言未通过, 期望结果'{0}', 实际结果'{1}'".format(h_res, real_res))
|
||||
raise
|
||||
else:
|
||||
raise TypeError("asserttype方法错误")
|
||||
|
@ -138,9 +138,9 @@ def assert_time(hope_res, real_res):
|
|||
allure.attach(name="期望响应时间", body=str(hope_time))
|
||||
allure.attach(name='实际响应时间', body=str(real_res))
|
||||
assert real_res <= hope_time
|
||||
logging.info("time断言通过, 期望响应时间{0}, 实际响应时间{1}".format(hope_time, real_res))
|
||||
logging.info("time断言通过, 期望响应时间'{0}', 实际响应时间'{1}'".format(hope_time, real_res))
|
||||
except AssertionError:
|
||||
logging.error("请求响应时间过长, 期望时间{0}, 实际时间{1}".format(hope_time, real_res))
|
||||
logging.error("请求响应时间过长, 期望时间'{0}', 实际时间'{1}'".format(hope_time, real_res))
|
||||
raise
|
||||
|
||||
|
||||
|
@ -167,9 +167,9 @@ def assert_sql(hope_res, real_res):
|
|||
d = d.decode("utf-8")
|
||||
assert str(r_res) == str(d)
|
||||
logging.info(
|
||||
"sql断言通过, 期望结果{0}, 实际结果{1},sql耗时{2:.5f}秒".format(datas, r_res, time.time() - t1))
|
||||
"sql断言通过, 期望结果'{0}', 实际结果'{1}',sql耗时{2:.5f}秒".format(datas, r_res, time.time() - t1))
|
||||
except AssertionError:
|
||||
logging.error("sql断言未通过, 期望结果{0}, 实际结果{1},sql耗时{2:.5f}秒".format(datas, r_res, time.time() - t1))
|
||||
logging.error("sql断言未通过, 期望结果'{0}', 实际结果'{1}',sql耗时{2:.5f}秒".format(datas, r_res, time.time() - t1))
|
||||
raise
|
||||
else:
|
||||
raise ValueError("获取json值失败,请检查jsonpath")
|
||||
|
|
|
@ -57,6 +57,10 @@ def sql_json(jspath, res):
|
|||
return jsonpath.jsonpath(res, jspath)[0]
|
||||
|
||||
|
||||
def url_param(paramname, param):
|
||||
return param[paramname]
|
||||
|
||||
|
||||
def random_int(scope):
|
||||
"""
|
||||
获取随机整型数据
|
||||
|
@ -173,10 +177,11 @@ def get_time(time_type, layout, unit="0,0,0,0,0"):
|
|||
return ti
|
||||
|
||||
|
||||
def replace_random(value, res=None):
|
||||
def replace_random(value, res=None, param=None):
|
||||
"""
|
||||
调用定义方法替换字符串
|
||||
:param res:
|
||||
:param param: 路径参数数据
|
||||
:param res: jsonpath使用的返回结果
|
||||
:param value:
|
||||
:return:
|
||||
"""
|
||||
|
@ -187,6 +192,7 @@ def replace_random(value, res=None):
|
|||
time_list = re.findall(r"\$GetTime\(time_type=(.*?),layout=(.*?),unit=([0-9],[0-9],[0-9],[0-9],[0-9])\)\$", value)
|
||||
choice_list = re.findall(r"\$Choice\((.*?)\)\$", value)
|
||||
sqljson_list = re.findall(r"\$json\((.*?)\)\$", value)
|
||||
urlparam_list = re.findall(r"\$url\((.*?)\)\$", value)
|
||||
|
||||
if len(int_list):
|
||||
# 获取整型数据替换
|
||||
|
@ -204,26 +210,26 @@ def replace_random(value, res=None):
|
|||
value = replace_random(value, res)
|
||||
elif len(string_list):
|
||||
# 获取字符串数据替换
|
||||
for j in string_list:
|
||||
pattern = re.compile(r'\$RandomString\(' + j + r'\)\$')
|
||||
key = str(random_string(j))
|
||||
for i in string_list:
|
||||
pattern = re.compile(r'\$RandomString\(' + i + r'\)\$')
|
||||
key = str(random_string(i))
|
||||
value = re.sub(pattern, key, value, count=1)
|
||||
value = replace_random(value, res)
|
||||
|
||||
elif len(float_list):
|
||||
# 获取浮点数数据替换
|
||||
for n in float_list:
|
||||
pattern = re.compile(r'\$RandomFloat\(' + n + r'\)\$')
|
||||
key = str(random_float(n))
|
||||
for i in float_list:
|
||||
pattern = re.compile(r'\$RandomFloat\(' + i + r'\)\$')
|
||||
key = str(random_float(i))
|
||||
value = re.sub(pattern, key, value, count=1)
|
||||
value = replace_random(value, res)
|
||||
|
||||
elif len(time_list):
|
||||
# 获取时间替换
|
||||
for m in time_list:
|
||||
if len(m[0]) and len(m[1]):
|
||||
pattern = re.compile(r'\$GetTime\(time_type=' + m[0] + ',layout=' + m[1] + ',unit=' + m[2] + r'\)\$')
|
||||
key = str(get_time(m[0], m[1], m[2]))
|
||||
for i in time_list:
|
||||
if len(i[0]) and len(i[1]):
|
||||
pattern = re.compile(r'\$GetTime\(time_type=' + i[0] + ',layout=' + i[1] + ',unit=' + i[2] + r'\)\$')
|
||||
key = str(get_time(i[0], i[1], i[2]))
|
||||
value = re.sub(pattern, key, value, count=1)
|
||||
else:
|
||||
print("$GetTime$参数错误,time_type, layout为必填")
|
||||
|
@ -236,6 +242,7 @@ def replace_random(value, res=None):
|
|||
key = str(choice_data(i))
|
||||
value = re.sub(pattern, key, value, count=1)
|
||||
value = replace_random(value, res)
|
||||
|
||||
elif len(sqljson_list):
|
||||
for i in sqljson_list:
|
||||
pattern = re.compile(r'\$json\(' + i.replace('$', "\$").replace('[', '\[') + r'\)\$')
|
||||
|
@ -243,6 +250,12 @@ def replace_random(value, res=None):
|
|||
value = re.sub(pattern, key, value, count=1)
|
||||
value = replace_random(value, res)
|
||||
|
||||
elif len(urlparam_list):
|
||||
for i in urlparam_list:
|
||||
pattern = re.compile(r'\$url\(' + i + r'\)\$')
|
||||
key = str(url_param(i, param))
|
||||
value = re.sub(pattern, key, value, count=1)
|
||||
value = replace_random(value, param)
|
||||
else:
|
||||
pass
|
||||
return value
|
||||
|
@ -250,68 +263,69 @@ def replace_random(value, res=None):
|
|||
|
||||
if __name__ == '__main__':
|
||||
int_num = "$RandomPosInt(1,333)$"
|
||||
str_num = '$RandomString($RandomPosInt(2,23)$)$'
|
||||
str_num = '$RandomString($RandomPosInt(2,23)$)$$RandomPosInt(1,333)$'
|
||||
float_num = '$RandomFloat($RandomPosInt(2,13)$,$RandomPosInt(2,13)$,$RandomPosInt(2,13)$)$'
|
||||
time_num = '$GetTime(time_type=else,layout=%Y-%m-%d %H:%M:%S,unit=0,0,0,0,0)$'
|
||||
choice_num = '$Choice($RandomPosInt(2,13)$)$'
|
||||
'$json($.data[-$RandomPosInt(1,5)$:])$'
|
||||
jsons = """
|
||||
select count(*) '$json($.data[-$RandomPosInt(1,5)$:])$'
|
||||
$RandomString($RandomPosInt(2,23)$)$
|
||||
) as ad
|
||||
"""
|
||||
js = """
|
||||
select count(*) '$GetTime(time_type=past,layout=%Y-%m-%d,unit=0,0,0,1,0)$' from (
|
||||
select
|
||||
dr.qr_code,
|
||||
alarm.device_id,
|
||||
alarm.grade,
|
||||
alarm.create_time,
|
||||
alarm.handler_status,
|
||||
alarm.work_order
|
||||
|
||||
from alarm
|
||||
inner join (
|
||||
select device.id,
|
||||
device.qr_code,
|
||||
device.region_id,
|
||||
region.enterprise_id,
|
||||
device.status,
|
||||
device.category_id
|
||||
from device
|
||||
inner join region
|
||||
on device.region_id = region.id
|
||||
and region.enterprise_id = 88
|
||||
) as dr
|
||||
on dr.qr_code = alarm.device_id and alarm.create_time >= '$GetTime(time_type=past,layout=%Y-%m-%d 00:00:00,unit=0,0,0,1,0)$' and alarm.create_time < '$GetTime(time_type=past,layout=%Y-%m-%d 00:00:00,unit=0,0,0,0,0)$'
|
||||
) as ad
|
||||
"""
|
||||
# jsons = """
|
||||
# select count(*) '$json($.data[-$RandomPosInt(1,5)$:])$'
|
||||
# $RandomString($RandomPosInt(2,23)$)$
|
||||
# ) as ad
|
||||
# """
|
||||
# js = """
|
||||
# select count(*) '$GetTime(time_type=past,layout=%Y-%m-%d,unit=0,0,0,1,0)$' from (
|
||||
# select
|
||||
# dr.qr_code,
|
||||
# alarm.device_id,
|
||||
# alarm.grade,
|
||||
# alarm.create_time,
|
||||
# alarm.handler_status,
|
||||
# alarm.work_order
|
||||
#
|
||||
# from alarm
|
||||
# inner join (
|
||||
# select device.id,
|
||||
# device.qr_code,
|
||||
# device.region_id,
|
||||
# region.enterprise_id,
|
||||
# device.status,
|
||||
# device.category_id
|
||||
# from device
|
||||
# inner join region
|
||||
# on device.region_id = region.id
|
||||
# and region.enterprise_id = 88
|
||||
# ) as dr
|
||||
# on dr.qr_code = alarm.device_id and alarm.create_time >= '$GetTime(time_type=past,layout=%Y-%m-%d 00:00:00,unit=0,0,0,1,0)$' and alarm.create_time < '$GetTime(time_type=past,layout=%Y-%m-%d 00:00:00,unit=0,0,0,0,0)$'
|
||||
# ) as ad
|
||||
# """
|
||||
# a = json.dumps(ini_yaml("homePageData.yml")["companyAlarm"])
|
||||
# print(type(ini_yaml("家庭详情.yml")[0]["data"]))
|
||||
# print(replace_random(int_num))
|
||||
# print(replace_random(str_num))
|
||||
# print(replace_random(float_num))
|
||||
# print(replace_random(time_num))
|
||||
res1 = {'code': 0, 'msg': 'ok',
|
||||
'data': [{'time': '2021-08-18', 'number': None}, {'time': '2021-08-19', 'number': None},
|
||||
{'time': '2021-08-20', 'number': 1}, {'time': '2021-08-21', 'number': None},
|
||||
{'time': '2021-08-22', 'number': None}, {'time': '2021-08-23', 'number': 9},
|
||||
{'time': '2021-08-24', 'number': 7}, {'time': '2021-08-25', 'number': 11},
|
||||
{'time': '2021-08-26', 'number': 2}, {'time': '2021-08-27', 'number': 1},
|
||||
{'time': '2021-08-28', 'number': None}, {'time': '2021-08-29', 'number': None},
|
||||
{'time': '2021-08-30', 'number': None}, {'time': '2021-08-31', 'number': 1},
|
||||
{'time': '2021-09-01', 'number': 2}, {'time': '2021-09-02', 'number': 4},
|
||||
{'time': '2021-09-03', 'number': 3}, {'time': '2021-09-04', 'number': 3},
|
||||
{'time': '2021-09-05', 'number': 1}, {'time': '2021-09-06', 'number': 7},
|
||||
{'time': '2021-09-07', 'number': 13}, {'time': '2021-09-08', 'number': 23},
|
||||
{'time': '2021-09-09', 'number': 21}, {'time': '2021-09-10', 'number': 11},
|
||||
{'time': '2021-09-11', 'number': 7}, {'time': '2021-09-12', 'number': 4},
|
||||
{'time': '2021-09-13', 'number': 22}, {'time': '2021-09-14', 'number': 19},
|
||||
{'time': '2021-09-15', 'number': 38}, {'time': '2021-09-16', 'number': 39}]}
|
||||
# res1 = {'code': 0, 'msg': 'ok',
|
||||
# 'data': [{'time': '2021-08-18', 'number': None}, {'time': '2021-08-19', 'number': None},
|
||||
# {'time': '2021-08-20', 'number': 1}, {'time': '2021-08-21', 'number': None},
|
||||
# {'time': '2021-08-22', 'number': None}, {'time': '2021-08-23', 'number': 9},
|
||||
# {'time': '2021-08-24', 'number': 7}, {'time': '2021-08-25', 'number': 11},
|
||||
# {'time': '2021-08-26', 'number': 2}, {'time': '2021-08-27', 'number': 1},
|
||||
# {'time': '2021-08-28', 'number': None}, {'time': '2021-08-29', 'number': None},
|
||||
# {'time': '2021-08-30', 'number': None}, {'time': '2021-08-31', 'number': 1},
|
||||
# {'time': '2021-09-01', 'number': 2}, {'time': '2021-09-02', 'number': 4},
|
||||
# {'time': '2021-09-03', 'number': 3}, {'time': '2021-09-04', 'number': 3},
|
||||
# {'time': '2021-09-05', 'number': 1}, {'time': '2021-09-06', 'number': 7},
|
||||
# {'time': '2021-09-07', 'number': 13}, {'time': '2021-09-08', 'number': 23},
|
||||
# {'time': '2021-09-09', 'number': 21}, {'time': '2021-09-10', 'number': 11},
|
||||
# {'time': '2021-09-11', 'number': 7}, {'time': '2021-09-12', 'number': 4},
|
||||
# {'time': '2021-09-13', 'number': 22}, {'time': '2021-09-14', 'number': 19},
|
||||
# {'time': '2021-09-15', 'number': 38}, {'time': '2021-09-16', 'number': 39}]}
|
||||
# print(replace_random(js, res=res1))
|
||||
t = "$GetTime(time_type=past,layout=13timestampDAY,unit=0,0,0,1,4)$"
|
||||
# print(replace_random(choice_num))
|
||||
print(replace_random(t))
|
||||
urls = "$url(home_id)$"
|
||||
print(replace_random(str_num))
|
||||
# pattern = re.compile(r'\$json\(' + '$.data.alarm[1].number'.replace('$',"\$").replace('[','\[') + r'\)\$')
|
||||
# # key = str(sql_json(i))
|
||||
# key = "123"
|
||||
|
|
|
@ -53,6 +53,8 @@ def {testtitle}(casedata):""".format(testtitle=item[0]))
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
ym_path = r'thirdUrl.yml'
|
||||
pagenames = "third_pages_1.py"
|
||||
# ym_path = r'thirdUrl.yml'
|
||||
# pagenames = "third_pages_1.py"
|
||||
ym_path = r'urlData.yml'
|
||||
pagenames = "saasApp_pages_1.py"
|
||||
write_case(ym_path,pagenames)
|
||||
|
|
|
@ -123,3 +123,19 @@ def powerFees(casedata):
|
|||
data=casedata["data"])
|
||||
return res, restime
|
||||
|
||||
|
||||
def functionList(casedata):
|
||||
data = urlData["functionList"]
|
||||
logging.info("{}".format(casedata["info"]))
|
||||
res, restime = apisend(host=data["host"], address=data["address"], method=data["method"], headers=casedata["headers"],
|
||||
data=casedata["data"])
|
||||
return res, restime
|
||||
|
||||
|
||||
def regionList(casedata):
|
||||
data = urlData["regionList"]
|
||||
logging.info("{}".format(casedata["info"]))
|
||||
res, restime = apisend(host=data["host"], address=data["address"], method=data["method"], headers=casedata["headers"],
|
||||
data=casedata["data"])
|
||||
return res, restime
|
||||
|
||||
|
|
|
@ -123,3 +123,19 @@ def powerFees(casedata):
|
|||
data=casedata["data"])
|
||||
return res, restime
|
||||
|
||||
|
||||
def functionList(casedata):
|
||||
data = urlData["functionList"]
|
||||
logging.info("{}".format(casedata["info"]))
|
||||
res, restime = apisend(host=data["host"], address=data["address"], method=data["method"], headers=casedata["headers"],
|
||||
data=casedata["data"])
|
||||
return res, restime
|
||||
|
||||
|
||||
def regionList(casedata):
|
||||
data = urlData["regionList"]
|
||||
logging.info("{}".format(casedata["info"]))
|
||||
res, restime = apisend(host=data["host"], address=data["address"], method=data["method"], headers=casedata["headers"],
|
||||
data=casedata["data"])
|
||||
return res, restime
|
||||
|
||||
|
|
|
@ -36,13 +36,10 @@ class Test_alarm(object):
|
|||
@pytest.mark.parametrize('casedata', paramData["alarmRank"], ids=[i["info"] for i in paramData["alarmRank"]])
|
||||
@pytest.mark.flaky(reruns=1, reruns_delay=1)
|
||||
@pytest.mark.run(order=1)
|
||||
def test_alarmRank(self,third_login ,setup_login, casedata):
|
||||
def test_alarmRank(self ,setup_login, casedata):
|
||||
casedata["headers"]["Authorization"] = "JWT " + setup_login["data"]["token"]
|
||||
webdata = thirdData["webalarm"][0]
|
||||
webdata["headers"]["Authorization"] = "JWT " + third_login["data"]["token"]
|
||||
webres=webalarm(webdata)[0]
|
||||
res, restime = alarmRank(casedata)
|
||||
asserting(hope_res=casedata["assert"], real_res=res, re_time=restime,third_data=webres)
|
||||
asserting(hope_res=casedata["assert"], real_res=res, re_time=restime)
|
||||
|
||||
@allure.story("Test_alarmDistribute")
|
||||
@pytest.mark.parametrize('casedata', paramData["alarmDistribute"], ids=[i["info"] for i in paramData["alarmDistribute"]])
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
# coding:utf-8
|
||||
"""
|
||||
@author: 井松
|
||||
@contact: 529548204@qq.com
|
||||
@file: test_function.py
|
||||
@time: 2021/10/8 15:02
|
||||
"""
|
||||
from test_suite.page.saasApp_pages import *
|
||||
# from test_suite.page.third_pages import *
|
||||
paramData = ini_yaml("functionData.yml")
|
||||
# thirdData = ini_yaml("thirdData.yml")
|
||||
|
||||
class Test_function(object):
|
||||
@allure.story("Test_functionList")
|
||||
@pytest.mark.parametrize('casedata', paramData["functionList"], ids=[i["info"] for i in paramData["functionList"]])
|
||||
@pytest.mark.flaky(reruns=1, reruns_delay=1)
|
||||
@pytest.mark.run(order=1)
|
||||
def test_functionList(self, setup_login, casedata):
|
||||
casedata["headers"]["Authorization"] = "JWT " + setup_login["data"]["token"]
|
||||
res, restime = functionList(casedata)
|
||||
asserting(hope_res=casedata["assert"], real_res=res, re_time=restime)
|
|
@ -29,8 +29,8 @@ class Test_login(object):
|
|||
@pytest.mark.parametrize('casedata', paramData["forgetPassword"], ids=[i["info"] for i in paramData["forgetPassword"]])
|
||||
@pytest.mark.flaky(reruns=1, reruns_delay=1)
|
||||
@pytest.mark.run(order=1)
|
||||
def test_forgetPassword(self, casedata):
|
||||
def test_forgetPassword(self, casedata,cache):
|
||||
res, restime = mobileCode(paramData["mobileCode"][1])
|
||||
casedata['data']['session_key'] = res["data"]['session_id']
|
||||
casedata['data']["param"]['session_key'] = cache.get('k',None)
|
||||
res, restime = forgetPassword(casedata)
|
||||
asserting(hope_res=casedata["assert"], real_res=res,re_time=restime)
|
||||
|
|
|
@ -29,7 +29,7 @@ class Test_power(object):
|
|||
@pytest.mark.parametrize('casedata', paramData["powerFees"], ids=[i["info"] for i in paramData["powerFees"]])
|
||||
@pytest.mark.flaky(reruns=1, reruns_delay=1)
|
||||
@pytest.mark.run(order=1)
|
||||
def test_powerFees_Fees(self, third_login, setup_login, casedata):
|
||||
def test_powerFees(self, third_login, setup_login, casedata):
|
||||
|
||||
casedata["headers"]["Authorization"] = "JWT " + setup_login["data"]["token"]
|
||||
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
# coding:utf-8
|
||||
"""
|
||||
@author: 井松
|
||||
@contact: 529548204@qq.com
|
||||
@file: test_region.py
|
||||
@time: 2021/10/8 16:11
|
||||
"""
|
||||
from test_suite.page.saasApp_pages import *
|
||||
# from test_suite.page.third_pages import *
|
||||
paramData = ini_yaml("regionData.yml")
|
||||
# thirdData = ini_yaml("thirdData.yml")
|
||||
|
||||
class Test_function(object):
|
||||
@allure.story("Test_functionList")
|
||||
@pytest.mark.parametrize('casedata', paramData["functionList"], ids=[i["info"] for i in paramData["functionList"]])
|
||||
@pytest.mark.flaky(reruns=1, reruns_delay=1)
|
||||
@pytest.mark.run(order=1)
|
||||
def test_functionList(self, setup_login, casedata):
|
||||
casedata["headers"]["Authorization"] = "JWT " + setup_login["data"]["token"]
|
||||
res, restime = functionList(casedata)
|
||||
asserting(hope_res=casedata["assert"], real_res=res, re_time=restime)
|
Loading…
Reference in New Issue