*** Settings ***
Documentation     Test suite for configuring subscriber for Top Down Approach test
Suite Setup       Read InputFile
Test Template     Configuring Subscriber Top Down Test
Library           Collections
Library           String
Library           OperatingSystem
Library           XML
Library           RequestsLibrary
Library           ../Framework/utils/utils.py
Library           ../Framework/restApi.py

*** Variables ***
${PATHFILE}       ${CURDIR}/data/Subscriber_TopDown.json

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

*** Keywords ***
Read InputFile
    ${SubscriberList}=    utils.jsonToList    ${PATHFILE}   SubscriberInfo 
    Set Suite Variable    ${slist}    ${SubscriberList}
    Set Global Variable    ${Subscriber_Id}    ${EMPTY}

Configuring Subscriber Top Down Test
    [Arguments]    ${type}    ${listIndex}
    Run Keyword If    "${type}" == "CREATE"    Post Subscriber    ${listIndex}
    Run Keyword If    "${type}" == "RETRIEVE"    Get Subscriber    ${listIndex}

Post Subscriber
    [Arguments]    ${listIndex}
    ${SubscriberList} =    Get Variable Value    ${slist}
    ${SubscriberDict}=    utils.listToDict    ${SubscriberList}    ${listIndex}
    ${api_result_status}    ${api_result_json}=    restApi.ApiPostReturnJson    VOLT_SUBSCRIBER    ${SubscriberDict}
    Should Be True    ${api_result_status}
    ${Subscriber_Id}=    Get From Dictionary    ${api_result_json}    id
    Set Global Variable    ${Subscriber_Id}

Get Subscriber
    [Arguments]    ${listIndex}
    Log    ${Subscriber_Id}
    ${json_result}=    restApi.ApiChameleonGet    VOLT_SUBSCRIBER    ${Subscriber_Id}
    Log    ${json_result}
    ${SubscriberList} =    Get Variable Value    ${slist}
    ${SubscriberDict}=    utils.listToDict    ${SubscriberList}    ${listIndex}
    Log    ${SubscriberDict}
    ${test_result}=    utils.compare_dict    ${SubscriberDict}    ${json_result}
    Should Be True    ${test_result}
