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

"""
case_tag:cmdc_api,cmdc列表查询条件验证_特价单品管理,2264,2264-62,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, "url1")
request_body = commonFuc().get_business_data(module, "payload1")
# 发送请求
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


# 获取特价单品信息
product_code = result["data"]["list"][0]["freseniusProduct"]["productCode"]
product_info = result["data"]["list"][0]["freseniusProduct"]["productName"]
material_code = result["data"]["list"][0]["freseniusProduct"]["materialCode"]
manufacturer_list = result["data"]["list"][0]["freseniusProduct"]["manufacturer"]
productLine_name = result["data"]["list"][0]["productLineName"]
description = result["data"]["list"][0]["freseniusProduct"]["description"]
manufacturerProduct_desc = func(result["data"]["list"][0]["freseniusProduct"]["manufacturerProductDesc"])
manufacturerProduct_no = func(result["data"]["list"][0]["freseniusProduct"]["manufacturerProductNo"])
customer_code = func(result["data"]["list"][0]["customerCode"])
customer_name = func(result["data"]["list"][0]["customerName"])
manufacturer_user_no = func(result["data"]["list"][0]["manufacturerUserNo"])
manufacturer_user_desc = func(result["data"]["list"][0]["manufacturerUserDesc"])
document_no = result["data"]["list"][0]["documentNo"]
group_price_status = result["data"]["list"][0]["groupPriceStatus"]

# 第三步进行查询条件验证
url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "url1")
request_body = commonFuc().get_business_data(module, "payload14", 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, document_no, group_price_status)

"""
 场景: 列表查询条件验证_特价单品管理
 用例名称：列表查询条件验证_特价单品管理
 输出：{"productCode":"%s"}
"""

# 发送请求
result = requests.post(url, json=request_body, headers=headers)
result = json.loads(result.content)

# 获取特价单品code
result = {"productCode": result["data"]["list"][0]["freseniusProduct"]["productCode"]}
# 获取预期结果
check_dict = commonFuc().get_business_data(module, "checkDict14", product_code)
# 断言实际结果中是否包含预期结果的内容
commonFuc().check_result(check_dict, result)
