接口测试中的查询比较

import json
import re

a = {
    "code": 0,
    "description": "",
    "lastUpdateTime": 0,
    "payload": {
        "currentPage": 0,
        "totalPages": 0,
        "totalCount": 2,
        "list": [
            {
                "id": 788380,
                "tradeNo": "788380",
                "realName": "yyyy",
                "mobile": "11111111111",
                "idCardNo": "3",
                "orderStatus": 4,
                "createDateTime": 1562249949000,
                "updateDateTime": 1562249949000,
                "opUserId": 0,
                "opUserName": "",
                "userId": 150045,
                "userName": None,
                "remark": "",
                "distributorId": 1,
                "distributorName": "Test",
                "financeProductId": 1,
                "financeProductName": "Test",
                "financeProductType": 1,
                "financeProductRentTime": 1,
                "financeProductReturnCarFlag": 1,
                "financeProductDownPayment": 3,
                "financeProductMonthlyRental": 3,
                "financeProductServiceCharge": 3,
                "financeProductGuaranteeDeposit": 3,
                "financeProductTailMoney": 3,
                "financeProductTailInstalmentFlag": 1,
                "vehicleId": 1,
                "vehicleName": "3",
                "vehicleSeries": "3",
                "vehicleModel": "2019款 180TURBO CVT 舒适版",
                "vehicleSaleId": 1,
                "vehicleSalePrice": 1000,
                "cityid": 110100,
                "cityname": "北京市",
                "colorName": None,
                "color": "#0D2E0F",
                "intentionalModel": "332019款 180TURBO CVT 舒适版"
            },
            {
                "id": 661939,
                "tradeNo": "661939",
                "realName": "yyyy",
                "mobile": "11111111111",
                "idCardNo": "3",
                "orderStatus": 4,
                "createDateTime": 1562249944000,
                "updateDateTime": 1562249944000,
                "opUserId": 0,
                "opUserName": "",
                "userId": 150045,
                "userName": None,
                "remark": "",
                "distributorId": 1,
                "distributorName": "Test",
                "financeProductId": 1,
                "financeProductName": "Test",
                "financeProductType": 1,
                "financeProductRentTime": 1,
                "financeProductReturnCarFlag": 1,
                "financeProductDownPayment": 3,
                "financeProductMonthlyRental": 3,
                "financeProductServiceCharge": 3,
                "financeProductGuaranteeDeposit": 3,
                "financeProductTailMoney": 3,
                "financeProductTailInstalmentFlag": 1,
                "vehicleId": 1,
                "vehicleName": "3",
                "vehicleSeries": "3",
                "vehicleModel": "2019款 180TURBO CVT 舒适版",
                "vehicleSaleId": 1,
                "vehicleSalePrice": 1000,
                "cityid": 110100,
                "cityname": "北京市",
                "colorName": None,
                "color": "#0D2E0F",
                "intentionalModel": "332019款 180TURBO CVT 舒适版"
            }
        ]
    }
}

=============================

#是否存在的查询
result = a["payload"]["list"]
ret = []
for i in result:
    ret.append(i["orderStatus"])
b=[2,5]
print(set(ret).issubset(set(b)))   #判断ret是否在b这个列表里面,存在返回True,不存在返回False


# 大小比较的查询
result = a["payload"]["list"]
ret = []
for i in result:
    ret.append(i["orderStatus"])
test=[status for status in ret if 6>=status >=5]    #存在返回True,不存在返回False
if not test :
    print("False")
else:
    print("True")





©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容