*** Settings ***
Documentation     Test suite for Subscriber verification
Suite Setup       Read InputFile
Test Template     Verify Subscriber functionality
Library           Collections
Library           String
Library           OperatingSystem
Library           XML
Library           RequestsLibrary
Library           ../Framework/utils/utils.py
Library           ../Framework/restApi.py

*** Variables ***
${PATHFILE}       ${CURDIR}/data/Ch_Subscriber.json
${PATHFILE2}      ${CURDIR}/data/Ch_putSubscriber.json

*** Test Cases ***    TYPE        LISTINDEX
Test Create Subscriber-1
                      CREATE      0

Test Get_Subscriber-1
                      RETRIEVE    0

Test Edit Subscriber-1
                      PUT         0

Test Create Subscriber-2
                      CREATE      1

Test Get_Subscriber-2
                      RETRIEVE    1

Test Edit Subscriber-2
                      PUT         1

Test Create Subscriber-3
                      CREATE      2

Test Get_Subcriber-3
                      RETRIEVE    2

Test Edit Subscriber-3
                      PUT         2

*** Keywords ***
Read InputFile
    ${subscriberList} =    utils.jsonToList    ${PATHFILE}    SubscriberInfo
    Set Suite Variable    ${slist}    ${subscriberList}
    ${putSubscriberList}=    utils.jsonToList    ${PATHFILE2}    SubscriberInfo
    Set Suite Variable    ${putList}    ${putSubscriberList}

Verify Subscriber functionality
    [Arguments]    ${type}    ${listIndex}
    Run Keyword If    "${type}" == "CREATE"    Test Post Subscriber API    ${listIndex}
    Run Keyword If    "${type}" == "RETRIEVE"    Test Get Subscriber API    ${listIndex}
    Run Keyword If    "${type}" == "DELETE"    Test Delete Subscriber API    ${listIndex}
    Run Keyword If    "${type}" == "PUT"    Test Edit Subscriber API    ${listIndex}

Test Post Subscriber API
    [Arguments]    ${listIndex}
    ${subscriberList} =    Get Variable Value    ${slist}
    ${subscriberDict}=    utils.listToDict    ${subscriberList}    ${listIndex}
    ${api_result}=    restApi.ApiPost    VOLT_SUBSCRIBER    ${subscriberDict}
    Should Be True    ${api_result}

Test Get Subscriber API
    [Arguments]    ${listIndex}
    ${json_result}=    restApi.ApiGet    VOLT_SUBSCRIBER
    Log    ${json_result}
    ${subscriberList}=    Get Variable Value    ${slist}
    ${subscriberDict}=    utils.listToDict    ${subscriberList}    ${listIndex}
    ${AccountNum}=    utils.getFieldValueFromDict    ${subscriberDict}    service_specific_id
    Log    ${AccountNum}
    ${json_result_list}=    Get From dictionary    ${json_result}    items
    ${getJsonDict}=    utils.getDictFromListOfDict    ${json_result_list}    service_specific_id    ${AccountNum}
    Log    ${getJsonDict}
    Log    ${subscriberDict}
    ${test_result}=    utils.compare_dict    ${subscriberDict}    ${getJsonDict}
    Should Be True    ${test_result}

Test Edit Subscriber API
    [Arguments]    ${listIndex}
    ${get_result}=    restApi.ApiGet    VOLT_SUBSCRIBER
    ${get_result_list}=    Get From Dictionary    ${get_result}    items
    ${putSubscriberList}=    Get Variable Value    ${putList}
    ${putSubscriberDict}=    utils.listToDict    ${putSubscriberList}    ${listIndex}
    ${AcctNum}=    utils.getFieldValueFromDict    ${putSubscriberDict}    service_specific_id
    Log    ${AcctNum}
    ${subscriberDict}=    utils.getDictFromListofDict    ${get_result_list}    service_specific_id    ${AcctNum}
    ${subscriberID}=    utils.getFieldValueFromDict    ${subscriberDict}    id
    ${api_result}=    restApi.ApiChameleonPut    VOLT_SUBSCRIBER    ${putSubscriberDict}    ${subscriberID}
    Should Be True    ${api_result}
    ${getResultAfterPut}=    restApi.ApiGet    VOLT_SUBSCRIBER
    ${getResultList_AfterPut}=    Get From Dictionary    ${getResultAfterPut}    items
    ${getResultDict}=    utils.getDictFromListOfDict    ${getResultList_AfterPut}    service_specific_id    ${AcctNum}
    ${test_result}=    utils.compare_dict    ${putSubscriberDict}    ${getResultDict}
    Should Be True    ${test_result}

Test Delete Subscriber API
    [Arguments]    ${listIndex}
    ${json_result}=    restApi.ApiGet    VOLT_SUBSCRIBER
    ${subscriberList}=    Get Variable Value    ${slist}
    ${subscriberDict}=    utils.listToDict    ${subscriberList}    ${listIndex}
    ${AcctNum}=    utils.getFieldValueFromDict    ${subscriberDict}    service_specific_id
    Log    ${AcctNum}
    ${subscriberDict}=    utils.getDictFromListofDict    ${json_result}    service_specific_id    ${AcctNum}
    Log    ${subscriberDict}
    ${subscriberId}=    utils.getFieldValueFromDict    ${subscriberDict}    id
    Log    ${subscriberId}
    ${test_result}=    restApi.ApiDelete    VOLT_SUBSCRIBER    ${subscriberId}
    Should Be True    ${test_result}
