*** Settings ***
Library           RequestsLibrary

*** Variables ***
${kfz}            api_tester    # 开发者账号
${zh}             api_test_admin    # 租管账号
${tenant_code}    API_test    # 租户号
${sa}             superAdmin    # superAdmin账号
${URL}            http://bitagent.sit.ninetechone.com
${client_id}      a68ad587830d41aebf418a919006353e

*** Test Cases ***
token生成
    Create Session    URL    http://accounts-4j.sit.ninetechone.com
    ${content}    生成token    ${kfz}    $SM4$Nd/e40vIS6UD9VMaSOmYGlrBORfo7r5/1z9D5d4E4es=$4MS$    ${tenant_code}    #加密后的密码
    Set Global Variable    ${a_token}    ${content["access_token"]}    #开发者access_token
    ${content}    生成token    ${zh}    $SM4$Nd/e40vIS6UD9VMaSOmYGlrBORfo7r5/1z9D5d4E4es=$4MS$    ${tenant_code}    #加密后的密码
    Set Global Variable    ${token}    Bearer ${content["access_token"]}    #开发者token
    Set Global Variable    ${zh_token}    Bearer ${content["access_token"]}    #租户管理员token
    Set Global Variable    ${URL}    ${URL}
    Set Global Variable    ${clientId}    ${client_id}
    #Set Global Variable    ${token}    Bearer 1a5188ab-00d9-4f40-867f-6305485a1dcd
    #Set Global Variable    ${zh_token}    Bearer 1a5188ab-00d9-4f40-867f-6305485a1dcd
    [Teardown]    Delete All Sessions

*** Keywords ***
生成token
    [Arguments]    ${un}    ${pw}    ${tenant_code}
    ${header}    Create Dictionary    Content-Type=application/x-www-form-urlencoded    Sm4-Key=dUVNkTJLlzMHPqBTZh085jT0N6S7930l6sgddJsYSC8=    Cookie=ENCRYPT_KEY=f48bf3-05fe-4978
    ${data}    Evaluate    json.loads('{"username":"${un}","password":"${pw}","tenantCode":"${tenant_code}","scope":"all","client_id":"a68ad587830d41aebf418a919006353e","client_secret":"Ninetech@123","grant_type":"password"}')    json
    ${resp}    post On Session    URL    /oauth/token    params=${data}    headers=${header}
    ${content}    Set Variable    ${resp.json()}
    [Return]    ${content}
