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

"""
case_tag:cmdc_api,cmdc站点无法快速下单,2250,2250-1,sit,bs
主数据平台:多采商城快速下单权限判定接口 
"""

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

module = "cmdc-qos"

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

# 第二步查询站点对应的companyId
url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "url1")
request_body = commonFuc().get_business_data(module, "payload1")

"""

 场景:站点不拥有快速下单权限入口
 用例名称：快速下单权限判定接口-站点满足条件显示快速下单入口
 输入：companyId
 输出："quickOrderSign": 0
"""
# 发送请求
result = requests.post(url, json=request_body, headers=headers)
result = json.loads(result.text)
# 获取站点对应的快速下单标识字段quickOrderSign
result1 = result["data"]

# 获取订单quickOrderSign进行判断处理
for i in result1:
    quick_order_sign = i["quickOrderSign"]
    # 第三步验证站点是否具有快速下单权限
    url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "url")
    if quick_order_sign == 0:
        # 获取companyId
        company_id = i["companyId"]
        request_body = commonFuc().get_business_data(module, "payload", company_id)
        result = requests.get(url, params=request_body)
        result = json.loads(result.text)
        # 获取预期结果
        check_dict = commonFuc().get_business_data(module, "checkDict2")
        # 断言实际结果中是否包含预期结果的内容
        commonFuc().check_result(check_dict, result)
        break
    else:
        # 获取companyId
        company_id = i["companyId"]
        request_body = commonFuc().get_business_data(module, "payload", company_id)
        result = requests.get(url, params=request_body)
        result = json.loads(result.text)
        # 获取预期结果
        check_dict = commonFuc().get_business_data(module, "checkDict1")
        # 断言实际结果中是否包含预期结果的内容
        commonFuc().check_result(check_dict, result)
        break

