class AssertCase:
def assertResponse(self, case, response):
"""
断言响应内容,更新用例执行情况
:paramcase:
:paramresponse:
:return:
"""
print("assertResponse")
print(case)
print(response)
assert_type = case['assert_type']
expect_result = case['expect_result']
is_pass =False
# 判断业务状态码
if isinstance(response,dict):
if response['root']:
r_root = response['root']
if r_root['head']:
r_head = r_root['head']
if assert_type =='code':
response_code = r_head['code']
if expect_result == response_code:
is_pass =True
print("测试用例通过")
else:
print("测试用例不通过")
is_pass =False
elif assert_type =='lenth':
response =len(response)
if int(response)>=int(expect_result):
is_pass =True
print("测试用例通过")
else:
print("测试用例不通过")
is_pass =False
elif assert_type =='data_json_array':
data_array = response['data']
if data_arrayis not None and isinstance(data_array, list)and len(data_array) >int(expect_result):
is_pass =True
print("测试用例通过")
else:
print("测试用例不通过")
is_pass =False
elif assert_type =='data_json':
data = response['data']
if datais not None and isinstance(data, list)and len(data) >int(expect_result):
is_pass =True
print("测试用例通过")
else:
print("测试用例不通过")
is_pass =False
if isinstance(response, dict):
if "Cookie" in response.keys():
msg =f"模块{case['case_module']},标题:{case['case_name']},断言类型:{assert_type},响应:{response['Cookie']}"
else:
msg =f"模块{case['case_module']},标题:{case['case_name']},断言类型:{assert_type},响应:{response}"
else:
msg =f"模块{case['case_module']},标题:{case['case_name']},断言类型:{assert_type},响应:{response}"
print(msg +"**********")
assert_msg = {"is_pass": is_pass, "msg": msg}
return assert_msg