*** Settings ***
Resource          ../../UserKeywords/UserKeywords_API.txt
Resource          ../../UserKeywords/UserKeywords_XML.txt

*** Variables ***
${EXOIUserName}    GlobalEquityData@morningstar.com
${EXOIPassword}    GXy1q88E
${EXOITestURL}    http://equitydata.xoi.morningstar.com/DataOutput.aspx?package=EquityData&Content=ShareClassInfoHistory&Id=0P000001R0&IdType=EquityShareClassId&Dates=2016
${OwnershipTestURL}    ownershipdata/api/GetData.aspx?function=GetOwnershipData&cusip=000360206&ownertype=MutualFund
${productId}      Direct
${userId}         42e5613b-49a0-4366-8cf7-480d21997883
${WebSite}        http://api-data.morningstar.com
${PayLoad}        {"sort": [{"sortorder": "ASC", "dp": "DIMCHAR75"}], "mandatory": ["TRI"], "dps": [{"alias": "DIMCHAR75", "dp": "DIMCHAR75"}, {"alias": "TRI", "param": {"15": "31", "14": "21", "17": "37", "16": "36"}, "dp": "FACT228"}], "name": "ColumnSetsNameAdd", "isStandard": false}
${GID_URL}        ${EMPTY}
${GID_Email}      bcee14b095766746177e10857ce6a0a56f3d0e978685c26b218fa295d3bf22de
${GID_Password}    fc6b8fc6a5b83dc6918f9cf79dfd1514
${GID_Input}      I2=0C000006WL
${GID_Output}     -2,1,2

*** Test Cases ***
API_Test_EXOI
    [Tags]    Sprint_x1    Sprint_y2    # Define the cases changeset in which sprint.
    ${APIReaderResult}    KW_API_ReadWebService_EXOI    ${EXOIUserName}    ${EXOIPassword}    ${EXOITestURL}
    Log    ${APIReaderResult.url}

API_Test_Ownership
    ${return_Webservice_XML}    KW_API_ReadWebService_Ownership    ${OwnershipTestURL}
    Log    ${return_Webservice_XML}

DataAPI_HttpGet
    ${header}    Create Dictionary    X-API-ProductId=${productId}    X-API-UserId=${userId}
    Create Session    httpbin    ${WebSite}
    ${resp}    Get Request    httpbin    /dataapi/v2/dataPoints/830/    headers=${header}
    ${Response_Content}    Set Variable    ${resp.content}
    ${Response_StatusCode}    Set Variable    ${resp.status_code}
    Log    ${Response_Content}
    log    ${Response_StatusCode}

DataAPI_HttpPost
    ${header}    Create Dictionary    X-API-ProductId=${productId}    X-API-UserId=${userId}
    Create Session    httpbin    ${WebSite}
    ${resp}    Post Request    httpbin    /dataapi/v2/columnSets    headers=${header}    data=${PayLoad}
    ${Response_Content}    Set Variable    ${resp.content}
    ${Response_StatusCode}    Set Variable    ${resp.status_code}
    Log    ${Response_Content}
    log    ${Response_StatusCode}

API_Test_GID
    [Documentation]    Read GID by input and output expr
    ${GID_URL}    KW_API_BuildURL_GID    ${GID_Input}    ${GID_Output}
    ${APIReaderResult}    KW_API_ReadWebService_GID    ${GID_URL}    ${GID_Email}    ${GID_Password}
    ${raw_obj}    KW_XML_XML2Obj    ${APIReaderResult}
    log    ${raw_obj.NewDataSet.GID.I2.cdata}
