# -*- encoding=utf8 -*-
__author__ = "liguangyu"

"""
case_tag:cmdc_api,cmdc查询条件验证_商品清单_结算页面,2288,2288-20,sit,bs
涉及到接口:多采商城获取商品清单接口
"""

from common.common_func import commonFuc
import requests
import json

module = "cmdc_order_handle"

# 第一步获取商品清单信息
url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "url15")
request_body = commonFuc().get_business_data(module, "payload15")
# 发送请求
result = requests.get(url, params=request_body)
result = json.loads(result.content)

# 获取商品信息
product_code = result["data"]["list"][0]["productCode"]
product_name = result["data"]["list"][0]["productName"]
material_code = result["data"]["list"][0]["materialCode"]
specifications = result["data"]["list"][0]["specifications"]

# 第二步进行商品查询
url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "url16")
request_body = commonFuc().get_business_data(module, "payload16", product_code, product_name, material_code, specifications)

"""

 场景: 查询条件验证_商品清单_结算页面
 用例名称：查询条件验证_商品清单_结算页面
 输出：{"productCode":"%s"}
"""

# 发送请求
result = requests.get(url, params=request_body)
# 获取接口响应时间
api_time = float(result.elapsed.total_seconds())
result = json.loads(result.content)
# 获取查询结果中商品信息
result = {"productCode": result["data"]["list"][0]["productCode"]}
result["api_time"] = api_time
# 获取预期结果
check_dict = commonFuc().get_business_data(module, "checkDict16", product_code)
# print(check_dict)
# 断言实际结果中是否包含预期结果的内容
commonFuc().check_result(check_dict, result)

