# -*- encoding=utf8 -*-
from common.fileUtls import FileUtils

__author__ = "xiaohesheng"

"""
case_tag:api,mdm-web,a1产品新增导入,id2251,id2251-1-2,sit,on
主数据平台:a1产品新增导入 
"""

from common.common_func import commonFuc
from airtest.core.api import using
import sys
module = "a5_mdm3_pdm"
def add_goods():
    # pro_path = commonFuc().get_pro_path()
    # sys.path.append(pro_path + r'\\air_case\\a4_mdm3_cm\\b17供货目录申请_客户类型_医院_企业账号登录.air')
    # using(pro_path + r'\\air_case\\a4_mdm3_cm\\b17供货目录申请_客户类型_医院_企业账号登录.air')
    # from b17供货目录申请_客户类型_医院_企业账号登录 import e_login
    # token, projectCode, uxid, corpId, e_name = e_login()
    # print(token, projectCode, uxid, corpId, e_name)
    #
    # sys.path.append(pro_path + r'\\air_case\\a4_mdm3_cm\\b10供货关系审核_驳回_客户类型_医院_医院账号登录.air')
    # using(pro_path + r'\\air_case\\a4_mdm3_cm\\b10供货关系审核_驳回_客户类型_医院_医院账号登录.air')
    # from b10供货关系审核_驳回_客户类型_医院_医院账号登录 import h_login
    # h_token, h_projectCode, h_uxid, h_corpId, h_name = h_login()
    pro_path = commonFuc().get_pro_path()
    sys.path.append(pro_path + r'\\air_case\\a4_mdm3_cm\\a2供货关系申请_客户类型_医院_登录_企业登录.air')
    using(pro_path + r'\\air_case\\a4_mdm3_cm\\a2供货关系申请_客户类型_医院_登录_企业登录.air')
    from a2供货关系申请_客户类型_医院_登录_企业登录 import e_login
    token, projectCode, uxid, corpId, e_name = e_login()
    # 获取医院corpId
    sys.path.append(pro_path + r'\\air_case\\a4_mdm3_cm\\a1供货关系申请_客户类型_医院_登录_医院登录获取医院id.air')
    using(pro_path + r'\\air_case\\a4_mdm3_cm\\a1供货关系申请_客户类型_医院_登录_医院登录获取医院id.air')
    from a1供货关系申请_客户类型_医院_登录_医院登录获取医院id import h_login
    h_token, h_projectCode, h_uxid, h_corpId, h_name = h_login()
    """
     场景:a1产品新增导入
     用例名称：a1产品新增导入
     输入：医院id
     输出："rtn_msg": 0
    """
    module = "a5_mdm3_pdm"
    #b18供货目录申请_客户类型_医院_提交供货申请单_添加产品
    url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "addGoodsHandleInfos_url")
    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            projectCode)
    goodsname = commonFuc().randomString(5)
    request_body = commonFuc().get_business_data(module, "payload_2", h_corpId,h_name,corpId,e_name,goodsname,e_name)
    # request_body = commonFuc().get_business_data(module, "payload10_1")

    # print('request_body',request_body)
    # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    print('result', result)
    #断言
    code=commonFuc().analysis_json('code',result)
    data=commonFuc().analysis_json('data',result)
    if code==0:
        commonFuc().check_text_exist(code,result)
    else:
        commonFuc().check_text_exist(-1, result)
add_goods()

