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

*** Variables ***
# Update the input file for olt_device_id before running the tests
${PATHFILE}       ${CURDIR}/data/PONPort.json

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

Test Get PONPort-1
                      RETRIEVE                     0
Test Delete PONPort-1
                      DELETE       0
Test Create PONPort-2
                      CREATE       1
Test Get PONPort-2
                      RETRIEVE     1
Test Delete PONPort-2
                      DELETE       1
Test Create PONPort-3
                      CREATE       2
Test Get PONPort-3
                      RETRIEVE     2
Test Delete PONPort-3
                      DELETE       2

*** Keywords ***
Read InputFile
    ${PONPortList}=    utils.jsonToList    ${PATHFILE}    PONPortInfo
    Set Suite Variable    ${plist}    ${PONPortList}
    Set Suite Variable    ${PONPort_Id}    ${EMPTY}

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

Test Post PONPort API
    [Arguments]    ${listIndex}
    ${PONPortList} =    Get Variable Value    ${plist}
    ${PONPortDict}=    utils.listToDict    ${PONPortList}    ${listIndex}
    ${api_result_status}    ${api_result_json}=    restApi.ApiPostReturnJson    PON_PORT    ${PONPortDict}
    Should Be True    ${api_result_status}
    ${PONPort_Id}=    Get From Dictionary    ${api_result_json}    id
    Set Global Variable    ${PONPort_Id}

Test Get PONPort API
    [Arguments]    ${listIndex}
    Log    ${PONPort_Id}
    ${json_result}=    restApi.ApiChameleonGet    PON_PORT    ${PONPort_Id}
    Log    ${json_result}
    ${PONPortList} =    Get Variable Value    ${plist}
    ${PONPortDict}=    utils.listToDict    ${PONPortList}    ${listIndex}
    Log    ${PONPortDict}
    ${test_result}=    utils.compare_dict    ${PONPortDict}    ${json_result}
    Should Be True    ${test_result}

Test Delete PONPort API
    [Arguments]    ${listIndex}
    ${test_result}=    restApi.ApiChameleonDelete    PON_PORT    ${PONPort_Id}
    Should Be True    ${test_result}
