*** Settings ***
Documentation     Test suite for volt Tenant Verification - Chameleon API
Suite Setup       Read InputFile
Test Template     Verify volt Tenant Functionality
Library           Collections
Library           String
Library           OperatingSystem
Library           XML
Library           RequestsLibrary
Library           ../Framework/utils/utils.py
Library           ../Framework/restApi.py

*** Variables ***
${USER}           admin
${PASSWORD}       admin
${PATHFILE}       ${CURDIR}/data/Ch_VoltTenant.json
${PATHFILE2}      ${CURDIR}/data/Ch_putVoltTenant.json

*** Test Cases ***    TYPE      LISTINDEX
Test volt Tenant-1    CREATE    0

Test volt Tenant-2    CREATE    1

Test volt Tenant-3    CREATE    2

*** Keywords ***
Read InputFile
    ${voltList} =    utils.jsonToList    ${PATHFILE}    voltSubscriberInfo
    Set Suite Variable    ${vlist}    ${voltList}
    ${putvoltList}=    utils.jsonToList    ${PATHFILE2}    voltSubscriberInfo
    Set Suite Variable    ${putList}    ${putvoltList}

Verify volt Tenant Functionality
    [Arguments]    ${type}    ${listIndex}
    Run Keyword If    "${type}" == "CREATE"    Test Post volt Tenant API    ${listIndex}

Test Post volt Tenant API
    [Arguments]    ${listIndex}
    ${voltTenantList} =    Get Variable Value    ${vlist}
    ${voltTenantDict}=    utils.listToDict    ${voltTenantList}    ${listIndex}
    ${voltDict}=    Get From Dictionary    ${voltTenantDict}    voltTenant
    ${service_specific_id}=    Get From Dictionary    ${voltTenantDict}    service_specific_id
    ${get_result}=    restApi.ApiGet    VOLT_SUBSCRIBER
    ${get_result_list}=    Get From Dictionary    ${get_result}    items
    ${subscriberDict}=    utils.getDictFromListofDict    ${get_result_list}    service_specific_id    ${service_specific_id}
    ${subscriberID}=    utils.getFieldValueFromDict    ${subscriberDict}    id
    Log    ${subscriberID}
    ${updatedVoltDict}=    utils.setFieldValueInDict    ${voltDict}    subscriber_root_id    ${subscriberID}
    ${api_result}=    restApi.ApiPost    VOLT_TENANT    ${updatedVoltDict}
    Should Be True    ${api_result}
    # Verifying Get operation after POST
    ${getVolt_result}=    restApi.ApiGet    VOLT_TENANT
    ${getVolt_result_list}=    Get From Dictionary    ${getVolt_result}    items
    ${getJsonDict}=    utils.getDictFromListOfDict    ${getVolt_result_list}    subscriber_root_id    ${subscriberID}
    ${test_result}=    utils.compare_dict    ${voltDict}    ${getJsonDict}
    Should Be True    ${test_result}
    # Verifying PUT operation
    ${putvoltList}=    Get Variable Value    ${putList}
    ${putVoltDict}=    utils.listToDict    ${putvoltList}    ${listIndex}
    ${putvoltTenantDict}=    Get From Dictionary    ${putVoltDict}    voltTenant
    ${voltID}=    utils.getFieldValueFromDict    ${getJsonDict}    id
    ${put_result}=    restApi.ApiChameleonPut    VOLT_TENANT    ${putvoltTenantDict}    ${voltID}
    Should Be True    ${put_result}
    # Verifying Get after PUT operation
    #${getVolt_afterPut}=    restApi.ApiGet    VOLT_TENANT
    #${getVoltDict}=    utils.getDictFromListofDict    ${getVolt_afterPut}    id    ${voltID}
    ${getVoltDict}=    utils.ApiChemeleonGet    VOLT_TENANT    ${voltID}
    ${result_afterPut}=    utils.compare_dict    ${putvoltTenantDict}    ${getVoltDict}
    Should Be True    ${result_afterPut}
