# -*- encoding=utf8 -*-

__author__ = "xiaohesheng"

"""
case_tag:api,herp-web,a_a6_手工采购计划_低值产品_暂存,id2297,id2297-6,sit,on
内网:a_a6_手工采购计划_低值产品_暂存 
"""

from common.common_func import commonFuc
from air_case.b1_herp3_login.登录内网系统.登录内网系统 import login_system
from airtest.core.api import using
import sys


def test1():
    module = "b3_herp3_purchase"
    """
     场景:a_a6_手工采购计划_低值产品_暂存
     用例名称：a_a6_手工采购计划_低值产品_暂存
     输入：无
     输出："rtn_msg": {"code": 0, "msg": null,    "data": true}
    """
    # 内网登录
    username = commonFuc().get_business_data(module, "username")
    # print('医院名称',username)
    password = commonFuc().get_business_data(module, "password")
    # print(username, password,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
    # 获取token和projectCode
    token, projectCode, uxid, corpId, info = login_system(username, password).get_token()
    # print( token,projectCode,uxid,corpId,info)
    #
    url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "herpService_purPlan_insert_url")
    print(url)
    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))
    print('headers', headers)
    # 产品是手术衣，跟外网配送相关联
    # # 请求体
    request_body = commonFuc().get_business_data(module, "payload")
    print('request_body', request_body)
    new_request_body = request_body.replace("'", '"')
    new_request_body = new_request_body.replace("None", 'null')
    # print(new_request_body)
    import json
    request_body_json = json.loads(new_request_body)
    print('request_body_json', request_body_json)
    # 发送请求
    result = commonFuc().http_post(url, request_body_json, headers)
    print('result', result)
    # 断言
    code = commonFuc().analysis_json('code', result)
    data = commonFuc().analysis_json('data', result)
    if code == 0 and len(data) >= 1:
        commonFuc().check_text_exist(0, result)
        print(data)
        return data
    else:
        commonFuc().check_text_exist('error', result)


test1()
