006、【MYY】接口自动化,用例断言
个人解答如下:
from jsonpath import jsonpath class TestUploadFile: def test_upload_file(self): response_data = { "Status Code": 200, "ret": { "id": "id", "imageList": [ { "originUrl": "图片链接1", "originWidth": 200, "originHeight": 300 }, { "originUrl": "图片链接2", "originWidth": 300, "originHeight": 300 } ] } } # 1、先断言响应状态码 status_code_actual_result = jsonpath(response_data, "$.Status Code")[0] status_code_expected_result = 200 assert status_code_actual_result == status_code_expected_result # 2、断言图片的信息 image_2_origin_url_actual_result = jsonpath(response_data, "$..originUrl")[1] image_2_origin_width_actual_result = jsonpath(response_data, "$..originWidth")[1] image_2_origin_height_actual_result = jsonpath(response_data, "$..originHeight")[1] actual_result_tuple = (image_2_origin_url_actual_result, image_2_origin_width_actual_result, image_2_origin_height_actual_result) expected_result_tuple = ("图片链接2", 300, 300) assert actual_result_tuple == expected_result_tuple # 3、由于这个像是上传图片,加上数据库断言比较合适。