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

"""
case_tag:cmdc_api,cmdc获取商品列表(快速下单),2252,2252-43,sit,bs
主数据平台:多采商城商品列表接口 
"""

from common.common_func import commonFuc
from air_case.cmdc_login.多采商城登录.多采商城登录 import CmdcMaiiLogin
import requests
import json


module = "cmdc_product_list_query"
# 第一步登录多采商城获取cmdc_access_token
# 获取登录所需账号密码
username = commonFuc().get_business_data(module, "username1")
password = commonFuc().get_business_data(module, "password1")
# 获取登录后Cmdc_access_token
cmdc_access_token = CmdcMaiiLogin(username, password).get_token()
headers = commonFuc().get_business_data(module, "json_headers1", cmdc_access_token)

# 第二步查询站点信息
url10 = commonFuc().get_api_url() + commonFuc().get_business_data(module, "url10")
request_body10 = commonFuc().get_business_data(module, "payload10")

# 发送请求
result10 = requests.post(url10, json=request_body10, headers=headers)
result10 = json.loads(result10.content)

# 获取站点companyId
company_id = result10["data"][3]["companyId"]
# 第二步查询站点对应的JDEcode
url11 = commonFuc().get_api_url() + commonFuc().get_business_data(module, "url11")
request_body11 = commonFuc().get_business_data(module, "payload11", company_id)

# 发送请求
result11 = requests.get(url11, params=request_body11, headers=headers)
result11 = json.loads(result11.content)
company_code = result11["data"]["companyCode"]

# 第四步切换站点
url12 = commonFuc().get_api_url() + commonFuc().get_business_data(module, "url12")
request_body12 = commonFuc().get_business_data(module, "payload12", company_id, company_code)

# 发送请求
result12 = requests.post(url12, json=request_body12, headers=headers)
result12 = json.loads(result12.content)

# 第四步查询站点对应的商品信息
url13 = commonFuc().get_api_url() + commonFuc().get_business_data(module, "url13")

"""
 场景:获取商品列表(快速下单)
 用例名称：获取商品列表(快速下单)
 输出：{"success":true,"code":"200","message":"OK","data":"ok"}
"""
# 发送请求
# request_body13 = commonFuc().get_business_data(module, "payload13")
# print(request_body13)
result = requests.get(url13, headers=headers)
result = json.loads(result.content)
# 获取预期结果
check_dict = commonFuc().get_business_data(module, "checkDict13")
print(check_dict)
# 断言实际结果中是否包含预期结果的内容
commonFuc().check_result(check_dict, result)

