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

"""
case_tag:cmdc_api,cmdc列表查询条件验证_套包正价管理,2264,2264-50,sit,bs
主数据平台:后台运营系统套包正价查询接口
"""

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

module = "cmdc_special_fresenius_group"

# 第一步登录后台运营平台获取cmdc_access_token
# 获取登录所需账号密码
username = commonFuc().get_business_data(module, "username1")
password = commonFuc().get_business_data(module, "password1")
# 获取登录后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, "url30")
request_body = commonFuc().get_business_data(module, "payload30")
# 发送请求
result = requests.post(url, json=request_body, headers=headers)
result = json.loads(result.content)


# 此函数用于当x为none时，进行空字符串替换
def func(x):
    if x is None:
        x = ""
        return x
    else:
        return x


# 获取套包信息
group_code = result["data"]["list"][0]["groupCode"]
group_name = result["data"]["list"][0]["groupName"]
product_code = result["data"]["list"][0]["products"][0]["productCode"]
product_info = result["data"]["list"][0]["products"][0]["productName"]
material_code = result["data"]["list"][0]["products"][0]["materialCode"]
manufacturer_list = result["data"]["list"][0]["products"][0]["manufacturer"]
productLine_name = result["data"]["list"][0]["productLineName"]
description = result["data"]["list"][0]["products"][0]["description"]
manufacturerProduct_desc = func(result["data"]["list"][0]["products"][0]["manufacturerProductDesc"])
manufacturerProduct_no = func(result["data"]["list"][0]["products"][0]["manufacturerProductNo"])
customer_code = func(result["data"]["list"][0]["products"][0]["customerCode"])
customer_name = func(result["data"]["list"][0]["products"][0]["customerName"])
manufacturer_user_no = func(result["data"]["list"][0]["products"][0]["manufacturerUserNo"])
manufacturer_user_desc = func(result["data"]["list"][0]["products"][0]["manufacturerUserDesc"])
status = result["data"]["list"][0]["status"]

# 第三步进行查询条件验证
url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "url30")
request_body = commonFuc().get_business_data(module, "payload31", group_code, group_name, product_code, product_info,
                                             material_code, manufacturer_list, productLine_name, description,
                                             manufacturerProduct_desc,
                                             manufacturerProduct_no, customer_code, customer_name, manufacturer_user_no,
                                             manufacturer_user_desc, status)

"""
 场景: 套包正价管理列表查询条件验证
 用例名称：列表查询条件验证_套包正价管理
 输出：{"groupCode":"%s"}
"""

# 发送请求
result = requests.post(url, json=request_body, headers=headers)
# 获取接口响应时间
api_time = float(result.elapsed.total_seconds())
result = json.loads(result.content)

# 获取套包正价信息groupCode
result = {"groupCode": result["data"]["list"][0]["groupCode"]}
result["api_time"] = api_time
# 获取预期结果
check_dict = commonFuc().get_business_data(module, "checkDict31", group_code)
# 断言实际结果中是否包含预期结果的内容
commonFuc().check_result(check_dict, result)
