Commit bc9e57e8 authored by Serafino's avatar Serafino
Browse files

added some utility keywords for distops test cases

parent 0fade250
Loading
Loading
Loading
Loading
+68 −0
Original line number Original line Diff line number Diff line
*** Settings ***
Variables       ${EXECDIR}/resources/variables.py
Library         ${EXECDIR}/libraries/logUtils.py
Library         RequestsLibrary
Library         Collections
Library         JSONLibrary
Library         String

***Variables***
${CONTENT_TYPE_LD_JSON}                     application/ld+json
${ENTITIES_ENDPOINT_PATH}                   entities

***Keywords***
Create Entity On Remote Broker
    [Arguments]    ${filename}    ${entity_id}
    ${entity_payload}=    Load JSON From File    ${EXECDIR}/data/entities/${filename}
    ${entity}=    Update Value To JSON
    ...    ${entity_payload}
    ...    $..id
    ...    ${entity_id}
    ${entity}=    Update Value To JSON
    ...    ${entity_payload}
    ...    $..id
    ...    ${entity_id}
    &{headers}=    Create Dictionary    Content-Type=application/ld+json
    ${response}=    POST
    ...    url=${remote_url}/${ENTITIES_ENDPOINT_PATH}
    ...    json=${entity}
    ...    headers=${headers}
    ...    expected_status=any
    Output    ${response}    Create Entity On Remote Broker
    RETURN    ${response}

Delete Entity by Id On Remote Broker
    [Arguments]    ${id}
    ${response}=    DELETE
    ...    url=${remote_url}/${ENTITIES_ENDPOINT_PATH}${id}
    ...    expected_status=any
    Output    ${response}    Delete Entity by Id On Remote Broker
    RETURN    ${response}

Create ContextSourceRegistration With Mode
    [Arguments]    ${id}    ${registration_file}    ${entity_id}=${EMPTY}    ${mode}=${EMPTY}
    
    ${payload}=    Load JSON From File    ${EXECDIR}/data/${registration_file}
    ${registration_payload}=    Update Value To JSON
    ...    ${payload}
    ...    $..id
    ...    ${id}
    ${registration_payload}=    Update Value To JSON
    ...    ${registration_payload}
    ...    $..endpoint
    ...    ${context_source_endpoint}
    IF    '${entity_id}' != ''
        ${dict}=    Create Dictionary    id=${entity_id}
        ${registration_payload}=    Add Object To JSON
        ...    ${registration_payload}
        ...    $..entities[*]
        ...    ${dict}
    END
    IF    '${mode}' != ''    
        ${dict}=    Create Dictionary    mode=${mode}
        ${registration_payload}=    Add Object To JSON
        ...    ${registration_payload}
        ...    $
        ...    ${dict}
    END
    RETURN    ${registration_payload}