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

"""
case_tag:cmdc_api,cmdc规格型号查询验证_植入上报列表,00,00-90,sit,bs
主数据平台:后台运营系统获取植入上报接口
"""

from common.common_func import commonFuc
from air_case.cmdc_login.后台管理系统登录.后台管理系统登录 import CmdcDoLogin
import random
import requests
import json

module = "cmdc_special_version"

# 获取登录所需账号密码
username = commonFuc().get_business_data(module, "username_uat")
password = commonFuc().get_business_data(module, "password_uat")
# 获取登录后Cmdc_access_token
cmdc_access_token = CmdcDoLogin(username, password).get_token()
headers = commonFuc().get_business_data(module, "json_headers", cmdc_access_token)

# 获取已配置的植入产品线信息
url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "url83")
request_body = commonFuc().get_business_data(module, "payload83")
# 发送请求
result = requests.post(url, json=request_body, headers=headers)
result = json.loads(result.content)

# 获取产品线信息
line_random = random.randint(0, len(result["data"]["list"]) - 1)
productLineCode = result["data"]["list"][line_random]["productLineCode"]

# 获取植入上报列表
url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "url85")
request_body = commonFuc().get_business_data(module, "payload85", productLineCode)
# 发送请求
result = requests.post(url, json=request_body, headers=headers)
result = json.loads(result.content)

# 获取植入上报信息
report_random = random.randint(0, len(result["data"]["list"]) - 1)
optionStr = result["data"]["list"][report_random]["optionStr"]

# 植入上报列表根据规格型号进行查询
url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "url90")
request_body = commonFuc().get_business_data(module, "payload90", optionStr, productLineCode)

"""
 场景: 规格型号查询验证_植入上报列表
 用例名称：规格型号查询验证_植入上报列表
 输出：{"optionStr": "%s"}
"""

# 发送请求
result = requests.post(url, json=request_body, headers=headers)
# 获取接口响应时间
api_time = float(result.elapsed.total_seconds())
result1 = json.loads(result.content)
# print(result)
# 获取查询结果对应的规格型号
result = {"optionStr": result1["data"]["list"][0]["optionStr"]}
result["api_time"] = api_time

# 获取预期结果
check_dict = commonFuc().get_business_data(module, "checkDict90", optionStr)
# print(check_dict)
# 断言实际结果中是否包含预期结果的内容
commonFuc().check_result(check_dict, result)


