增加多接口验证

This commit is contained in:
jing song 2022-04-19 10:52:26 +08:00
parent 9713044de3
commit eb5033b0c9
1 changed files with 22 additions and 20 deletions

View File

@ -13,10 +13,9 @@ from util.tools.readYamlFile import ini_yaml
Log()
def assert_text(hope_res, real_res, third_data=None, third_datas=None):
def assert_text(hope_res, real_res, third_data=None):
"""
文本判断
:param third_datas:
:param third_data:
:param hope_res: 期望结果
:param real_res: 实际结果
@ -28,29 +27,27 @@ def assert_text(hope_res, real_res, third_data=None, third_datas=None):
r_res = jsonpath.jsonpath(real_res, h_res["path"])[0]
if h_res["asserttype"] == "==":
try:
if not third_datas:
if third_data:
third_datas = eval(third_data)
h_res["value"] = replace_random(str(h_res["value"]), res=third_data)
with allure.step("json断言判断相等"):
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))
elif third_datas:
if h_res["relevanceCheck"]:
h_res["value"] = replace_random(str(h_res["value"]),
res=third_datas[h_res["relevanceCheck"]])
with allure.step("json断言判断相等"):
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))
if isinstance(third_data,str):
try:
third_data = eval(third_data)
except TypeError:
raise "third_data格式错误"
h_res["value"] = replace_random(str(h_res["value"]), res=third_data)
with allure.step("json断言判断相等"):
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))
except AssertionError:
logging.error("json断言未通过, 期望结果'{0}', 实际结果'{1}'".format(h_res, r_res))
raise
elif h_res["asserttype"] == "!=":
try:
if isinstance(third_data,str):
try:
third_data = eval(third_data)
except TypeError:
raise "third_data格式错误"
h_res["value"] = replace_random(str(h_res["value"]), res=third_data)
with allure.step("json断言判断不等"):
allure.attach(name="json期望结果", body=str(h_res))
@ -63,6 +60,11 @@ def assert_text(hope_res, real_res, third_data=None, third_datas=None):
elif h_res["asserttype"] == "in":
r_res = str(r_res)
try:
if isinstance(third_data,str):
try:
third_data = eval(third_data)
except TypeError:
raise "third_data格式错误"
h_res["value"] = replace_random(str(h_res["value"]), res=third_data)
with allure.step("json断言判断包含"):
allure.attach(name="期望结果", body=str(h_res))