*** Settings ***
Documentation     Test suite for checking the subscriber status after discovery
Suite Setup       Read InputFile
Test Template     Subscriber Status 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
&{input_dict}    mac_address=test    ip_address=test2
&{status}    status=test

*** Test Cases ***    TYPE                         LISTINDEX
Test Status Subscriber-1
                      STATUS                       0
Change Subscriber status
                      STATUSCHANGE             0
Push MACandIP Subscriber-1
                      PUSH                     0
Test Status Subscriber-2
                      STATUS                       1
Change Subscriber-2 status
                      STATUSCHANGE             1
Push MACandIP Subscriber-2
                      PUSH                     1

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

Subscriber Status Test
    [Arguments]    ${type}    ${listIndex}
    Run Keyword If    "${type}" == "PUSH"    Push MAC and IP For Subscriber    ${listIndex}
    Run Keyword If    "${type}" == "STATUS"    Subscriber Status Check    ${listIndex}
    Run Keyword If    "${type}" == "STATUSCHANGE"    Subscriber Status Change   ${listIndex}

Subscriber Status Check
    [Arguments]    ${listIndex}
    Set Global Variable    ${Subscriber_Id}    ${EMPTY}
    Log    ${Subscriber_Id}
    ${json_result}=    restApi.ApiGet    VOLT_SUBSCRIBER
    Log    ${json_result}
    ${SubscriberList} =    Get Variable Value    ${slist}
    ${SubscriberDict}=    utils.listToDict    ${SubscriberList}    ${listIndex}
    Log    ${SubscriberDict}
    ${onu_device}=    utils.getFieldValueFromDict    ${subscriberDict}   onu_device
    ${json_result_list}=    Get From dictionary    ${json_result}    items
    ${getJsonDict}=    utils.getDictFromListOfDict    ${json_result_list}    onu_device    ${onu_device}
    ${status}=	Get From Dictionary    ${getJsonDict}    status
    ${Subscriber_Id}=    Get From Dictionary    ${getJsonDict}   id
    Set Global Variable    ${Subscriber_Id}
    Should Be Equal    ${status}    awaiting_auth
    #Set Global Variable    ${Subscriber_Id}

Subscriber Status Change
    [Arguments]    ${listIndex}
    ${status}=    Create Dictionary    status=enabled
    ${api_result_status}=    restApi.ApiChameleonPut    VOLT_SUBSCRIBER    ${status}    ${Subscriber_Id}
    Should Be True    ${api_result_status}

Push MAC and IP For Subscriber
    [Arguments]    ${listIndex}
    ${SubscriberList} =    Get Variable Value    ${slist}
    ${SubscriberDict}=    utils.listToDict    ${SubscriberList}    ${listIndex}
    ${mac_address}=    utils.getFieldValueFromDict    ${subscriberDict}   mac_address
    ${ip_address}=    utils.getFieldValueFromDict    ${subscriberDict}   ip_address
    ${input_dict}=    Create Dictionary    mac_address=${mac_address}    ip_address=${ip_address}
    ${api_result_status}=    restApi.ApiChameleonPut    VOLT_SUBSCRIBER    ${input_dict}    ${Subscriber_Id}
    Should Be True    ${api_result_status}
