diff --git "a/air_case/cmdc_product/\346\230\216\347\273\206\345\257\274\345\207\272\351\252\214\350\257\201.air/\346\230\216\347\273\206\345\257\274\345\207\272\351\252\214\350\257\201.py" "b/air_case/cmdc_product/\346\230\216\347\273\206\345\257\274\345\207\272\351\252\214\350\257\201.air/\346\230\216\347\273\206\345\257\274\345\207\272\351\252\214\350\257\201.py" index d78794e2223befafbbc1597c9bc229624519faf7..0ec4e2ad0db0912e763e4ee8b00c80dc6094e4ae 100644 --- "a/air_case/cmdc_product/\346\230\216\347\273\206\345\257\274\345\207\272\351\252\214\350\257\201.air/\346\230\216\347\273\206\345\257\274\345\207\272\351\252\214\350\257\201.py" +++ "b/air_case/cmdc_product/\346\230\216\347\273\206\345\257\274\345\207\272\351\252\214\350\257\201.air/\346\230\216\347\273\206\345\257\274\345\207\272\351\252\214\350\257\201.py" @@ -32,44 +32,46 @@ request_body = commonFuc().get_business_data(module, "payload1") result = requests.post(url, json=request_body, headers=headers) result = json.loads(result.content) -# 生成随机数 -random_demand = random.randint(0, len(result["data"]["list"]) - 1) -# 获取商品属性信息 -product_code = result["data"]["list"][random_demand]["productCode"] +# 判断是否存在商品属性信息 +if result["data"]["list"]: + # 生成随机数 + random_demand = random.randint(0, len(result["data"]["list"]) - 1) + # 获取商品属性信息 + product_code = result["data"]["list"][random_demand]["productCode"] -# 第三步进行明细导出操作 -url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "url9") -request_body = commonFuc().get_business_data(module, "payload9", product_code) -# print(request_body) -""" - - 场景: 商品属性明细导出验证 - 用例名称:商品属性明细导出验证 - 输出:{"productCode":"%s"} -""" + # 第三步进行明细导出操作 + url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "url9") + request_body = commonFuc().get_business_data(module, "payload9", product_code) + # print(request_body) + """ + + 场景: 商品属性明细导出验证 + 用例名称:商品属性明细导出验证 + 输出:{"productCode":"%s"} + """ -# 发送请求 -result = requests.post(url, json=request_body, headers=headers) -# 获取接口响应时间 -api_time = float(result.elapsed.total_seconds()) + # 发送请求 + result = requests.post(url, json=request_body, headers=headers) + # 获取接口响应时间 + api_time = float(result.elapsed.total_seconds()) -# 获取文件 -BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) -file_path = BASE_DIR + "/data/cmdc_files/商品属性导出明细.xlsx" + # 获取文件 + BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) + file_path = BASE_DIR + "/data/cmdc_files/商品属性导出明细.xlsx" -# 获取到导出文件存入cmdc_files文件中 -with open(file_path, 'wb') as f: - f.write(result.content) + # 获取到导出文件存入cmdc_files文件中 + with open(file_path, 'wb') as f: + f.write(result.content) -# 获取导出明细文件中商品code -excel = HandleExcel(file_path, "商品属性") -result = {"productCode": excel.read_data()[0].get("商品编码")} + # 获取导出明细文件中商品code + excel = HandleExcel(file_path, "商品属性") + result = {"productCode": excel.read_data()[0].get("商品编码")} -result["api_time"] = api_time -# print(result) -# 获取预期结果 -check_dict = commonFuc().get_business_data(module, "checkDict9", product_code) -# print(check_dict) -# 断言实际结果中是否包含预期结果的内容 -commonFuc().check_result(check_dict, result) + result["api_time"] = api_time + # print(result) + # 获取预期结果 + check_dict = commonFuc().get_business_data(module, "checkDict9", product_code) + # print(check_dict) + # 断言实际结果中是否包含预期结果的内容 + commonFuc().check_result(check_dict, result)