*** Settings ***
Documentation     Test suite for Deletion of Subscribers and voltTenants
Suite Setup       Read InputFile
Test Template     Verify Deletion of Subscriber and volt Tenant functionality
Library           Collections
Library           String
Library           OperatingSystem
Library           XML
Library           RequestsLibrary
Library           CORDRobot
Library           ImportResource  resources=CORDRobot

*** Variables ***
${USER}           admin
${PASSWORD}       admin
${PATHFILE}       ${CURDIR}/data/VoltTenant.json

*** Test Cases ***    TYPE      LISTINDEX
Test Delete Subscriber and volt_tenant-1
                      DELETE    0

Test Delete Subscriber and volt_tenant-2
                      DELETE    1

Test Delete Subscriber and volt_tenant-3
                      DELETE    2

*** Keywords ***
Read InputFile
    ${voltList} =    CORDRobot.jsonToList    ${PATHFILE}    voltSubscriberInfo
    Set Suite Variable    ${vlist}    ${voltList}

Verify Deletion of Subscriber and volt Tenant functionality
    [Arguments]    ${type}    ${listIndex}
    Run Keyword If    "${type}" == "DELETE"    Test Delete Subscriber and voltTenant    ${listIndex}

Test Delete Subscriber and voltTenant
    [Arguments]    ${listIndex}
    ${getSubscriber_result}=    CORDRobot.ApiGet    TENANT_SUBSCRIBER
    ${getVoltTenant_result}=    CORDRobot.ApiGet    TENANT_VOLT
    ${voltList}=    Get Variable Value    ${vlist}
    ${voltTenantDict}=    CORDRobot.listToDict    ${voltList}    ${listIndex}
    ${voltDict}=    Get From Dictionary    ${voltTenantDict}    voltTenant
    ${account_num}=    Get From Dictionary    ${voltTenantDict}    account_num
    ${subscriberDict}=    CORDRobot.getDictFromListofDict    ${getSubscriber_result}    account_num    ${account_num}
    Log    ${subscriberDict}
    ${subscriberId}=    CORDRobot.getFieldValueFromDict    ${subscriberDict}    id
    Log    ${subscriberId}
    ${subscriber_delete_result}=    CORDRobot.ApiDelete    TENANT_SUBSCRIBER    ${subscriberId}
    Should Be True    ${subscriber_delete_result}
    # Deletion of volt Tenants
    ${getVoltDict}=    CORDRobot.getDictFromListOfDict    ${getVoltTenant_result}    subscriber    ${subscriberId}
    ${voltID}=    CORDRobot.getFieldValueFromDict    ${getVoltDict}    id
    ${volt_delete_result}=    CORDRobot.ApiDelete    TENANT_VOLT    ${voltID}
    Should Be True    ${volt_delete_result}
