*** Settings ***
Documentation     Test to Configure White List
Suite Setup       Read InputFile
Test Template     Configuring White List
Library           Collections
Library           String
Library           OperatingSystem
Library           XML
Library           RequestsLibrary
Library           ../../Framework/utils/utils.py
Library           ../../Framework/restApi.py

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

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

*** Keywords ***
Read InputFile
    ${AttWhiteListList}=    utils.jsonToList    ${PATHFILE}   AttWhiteListInfo 
    Set Suite Variable    ${slist}    ${AttWhiteListList}
    Set Global Variable    ${AttWorkFlowDriver_Id}    ${EMPTY}
    Set Global Variable    ${AttWhiteList_Id}    ${EMPTY}

Configuring White List
    [Arguments]    ${type}    ${listIndex}
    Run Keyword If    "${type}" == "CREATE"    Post White List    ${listIndex}
    Run Keyword If    "${type}" == "RETRIEVE"    Get White List    ${listIndex}

Post White List
    [Arguments]    ${listIndex}
    ${AttWhiteListList} =    Get Variable Value    ${slist}
    ${AttWhiteListDict}=    utils.listToDict    ${AttWhiteListList}    ${listIndex}
    # Retrieve ATT Service Driver Id
    ${api_getResult}=    restApi.ApiGet    ATT_SERVICE
    ${AttWorkFlowDriverList}=    Get From Dictionary    ${api_getResult}    items
    ${AttWorkFlowDriverDict}=    utils.getDictFromListOfDict    ${AttWorkFlowDriverList}    leaf_model_name    AttWorkflowDriverService
    ${AttWorkFlowDriver_Id}=    Get From Dictionary    ${AttWorkFlowDriverDict}    id
    ${AttWhiteListDict}=    utils.setFieldValueInDict    ${AttWhiteListDict}    owner_id    ${AttWorkFlowDriver_Id}
    Log    ${AttWhiteListDict}
    ${api_result_status}    ${api_result_json}=    restApi.ApiPostReturnJson    ATT_WHITELIST    ${AttWhiteListDict}
    Should Be True    ${api_result_status}
    ${AttWhiteList_Id}=    Get From Dictionary    ${api_result_json}    id
    Set Global Variable    ${AttWhiteList_Id}

Get White List
    [Arguments]    ${listIndex}
    Log    ${AttWhiteList_Id}
    ${json_result}=    restApi.ApiChameleonGet    ATT_WHITELIST    ${AttWhiteList_Id}
    Log    ${json_result}
    ${AttWhiteListList} =    Get Variable Value    ${slist}
    ${AttWhiteListDict}=    utils.listToDict    ${AttWhiteListList}    ${listIndex}
    Log    ${AttWhiteListDict}
    ${test_result}=    utils.compare_dict    ${AttWhiteListDict}    ${json_result}
    Should Be True    ${test_result}
