Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects

Draft: :sparkles: Add redirect changes to RPS plugin

Open Frederico SEQUEIRA requested to merge v3_rps_redirect_changes into develop
+ 132
0
 
*** Settings ***
 
Test Tags mac
 
Library RequestsLibrary
 
Library OperatingSystem
 
Library Collections
 
Library DateTime
 
Variables ../variables.yaml
 
 
*** Variables ***
 
${BASE_URL} http://${HOST}:${PORT}
 
${MAPPING_ENDPOINT} /api/plugins/rps/mapping/
 
${REDIRECT_ENDPOINT} /api/plugins/rps/redirect/
 
${TOKEN} Token ${API_TOKEN}
 
 
*** Test Cases ***
 
 
Create Mapping for testing
 
${HEADERS} Create Dictionary Content-Type ${CONTENT_TYPE} Authorization ${TOKEN}
 
${payload} Create Dictionary source http://testsource.com target http://testtarget.com
 
${response}= POST ${BASE_URL}${MAPPING_ENDPOINT} json=${payload} headers=${HEADERS} expected_status=201
 
${json} Set Variable ${response.json()}
 
Convert to Dictionary ${json}
 
${MAPPING_ID} Get From Dictionary ${json} id
 
Set Global Variable ${MAPPING_ID}
 
 
Create Valid Mapping Redirect
 
${HEADERS} Create Dictionary Content-Type ${CONTENT_TYPE} Authorization ${TOKEN}
 
${NOW}= get time
 
${payload} Create Dictionary source http://testsource.com/A target http://testtarget.com/B mapping ${MAPPING_ID} redirect_type 1-1 activation_date ${NOW}
 
${response}= POST ${BASE_URL}${REDIRECT_ENDPOINT} json=${payload} headers=${HEADERS} expected_status=201
 
${json} Set Variable ${response.json()}
 
Convert to Dictionary ${json}
 
${REDIRECT_ID} Get From Dictionary ${json} id
 
Set Global Variable ${REDIRECT_ID}
 
 
Create 2nd Valid Mapping Redirect
 
${HEADERS} Create Dictionary Content-Type ${CONTENT_TYPE} Authorization ${TOKEN}
 
${NOW}= get time
 
${payload} Create Dictionary source http://testsource.com/Z target http://testtarget.com/B mapping ${MAPPING_ID} redirect_type 1-1 activation_date ${NOW} deactivation_date 2999-01-01T15:53:01.622818Z
 
${response}= POST ${BASE_URL}${REDIRECT_ENDPOINT} json=${payload} headers=${HEADERS} expected_status=201
 
${json} Set Variable ${response.json()}
 
Convert to Dictionary ${json}
 
${REDIRECT_ID} Get From Dictionary ${json} id
 
Set Global Variable ${REDIRECT_ID}
 
 
Create Duplicaded Redirect
 
${HEADERS} Create Dictionary Content-Type ${CONTENT_TYPE} Authorization ${TOKEN}
 
${NOW}= get time
 
${payload} Create Dictionary source http://testsource.com/A target http://testtarget.com/B mapping ${MAPPING_ID} redirect_type 1-1 activation_date ${NOW}
 
${response}= POST ${BASE_URL}${REDIRECT_ENDPOINT} json=${payload} headers=${HEADERS} expected_status=400
 
${json} Set Variable ${response.json()}
 
Convert to Dictionary ${json}
 
${ERROR} Get From Dictionary ${json} source
 
Should Contain ${ERROR} A Redirect with the same source and overlapping timespan already exists.
 
 
Create Incomplete Redirect- Missing Source
 
${HEADERS} Create Dictionary Content-Type ${CONTENT_TYPE} Authorization ${TOKEN}
 
${NOW}= get time
 
${payload} Create Dictionary target http://testtarget.com/B mapping ${MAPPING_ID} redirect_type 1-1 activation_date ${NOW}
 
${response}= POST ${BASE_URL}${REDIRECT_ENDPOINT} json=${payload} headers=${HEADERS} expected_status=400
 
${json} Set Variable ${response.json()}
 
Convert to Dictionary ${json}
 
${ERROR} Get From Dictionary ${json} source
 
Should Contain ${ERROR} This field is required.
 
 
Create Incomplete Redirect- Missing Target
 
${HEADERS} Create Dictionary Content-Type ${CONTENT_TYPE} Authorization ${TOKEN}
 
${NOW}= get time
 
${payload} Create Dictionary source http://testsource.com/C mapping ${MAPPING_ID} redirect_type 1-1 activation_date ${NOW}
 
${response}= POST ${BASE_URL}${REDIRECT_ENDPOINT} json=${payload} headers=${HEADERS} expected_status=400
 
${json} Set Variable ${response.json()}
 
Convert to Dictionary ${json}
 
${ERROR} Get From Dictionary ${json} target
 
Should Contain ${ERROR} This field is required.
 
 
Create Incomplete Redirect- Missing Mapping
 
${HEADERS} Create Dictionary Content-Type ${CONTENT_TYPE} Authorization ${TOKEN}
 
${NOW}= get time
 
${payload} Create Dictionary source http://testsource.com/C target http://testtarget.com/B redirect_type 1-1 activation_date ${NOW}
 
${response}= POST ${BASE_URL}${REDIRECT_ENDPOINT} json=${payload} headers=${HEADERS} expected_status=400
 
${json} Set Variable ${response.json()}
 
Convert to Dictionary ${json}
 
${ERROR} Get From Dictionary ${json} mapping
 
Should Contain ${ERROR} This field is required.
 
 
Create Incomplete Redirect- Check Date Default
 
${HEADERS} Create Dictionary Content-Type ${CONTENT_TYPE} Authorization ${TOKEN}
 
${NOW}= get time
 
${payload} Create Dictionary source http://testsource.com/datedefault target http://testtarget.com/B mapping ${MAPPING_ID} redirect_type 1-1
 
${response}= POST ${BASE_URL}${REDIRECT_ENDPOINT} json=${payload} headers=${HEADERS} expected_status=201
 
${json} Set Variable ${response.json()}
 
Convert to Dictionary ${json}
 
${DATE_DEFAULT} Get From Dictionary ${json} activation_date
 
${CONVERTED_DATE_DEFAULT} Convert Date ${DATE_DEFAULT} result_format=%d %b %Y %I:%M %p
 
${CONVERTED_NOW} Convert Date ${NOW} result_format=%d %b %Y %I:%M %p
 
Should Be Equal As Strings ${CONVERTED_DATE_DEFAULT} ${CONVERTED_NOW}
 
 
Create Incomplete Redirect- Check Type Default
 
${HEADERS} Create Dictionary Content-Type ${CONTENT_TYPE} Authorization ${TOKEN}
 
${NOW}= get time
 
${payload} Create Dictionary source http://testsource.com/typedefault target http://testtarget.com/B mapping ${MAPPING_ID} activation_date ${NOW}
 
${response}= POST ${BASE_URL}${REDIRECT_ENDPOINT} json=${payload} headers=${HEADERS} expected_status=201
 
${json} Set Variable ${response.json()}
 
Convert to Dictionary ${json}
 
${TYPE_DEFAULT} Get From Dictionary ${json} redirect_type
 
Should Be Equal As Strings ${TYPE_DEFAULT} 1-1
 
 
Create Invalid (Not the same source) Redirect
 
${HEADERS} Create Dictionary Content-Type ${CONTENT_TYPE} Authorization ${TOKEN}
 
${NOW}= get time
 
${payload} Create Dictionary source http://testsource_wrong.com/A target http://testtarget.com/B mapping ${MAPPING_ID} redirect_type 1-1 activation_date ${NOW}
 
${response}= POST ${BASE_URL}${REDIRECT_ENDPOINT} json=${payload} headers=${HEADERS} expected_status=400
 
${json} Set Variable ${response.json()}
 
Convert to Dictionary ${json}
 
${ERROR} Get From Dictionary ${json} source
 
Should Contain ${ERROR} Redirect source must start with the mapping's source.
 
 
Create Overlaped Dates Redirect
 
${HEADERS} Create Dictionary Content-Type ${CONTENT_TYPE} Authorization ${TOKEN}
 
${NOW}= get time
 
${payload} Create Dictionary source http://testsource.com/Z target http://testtarget.com/B mapping ${MAPPING_ID} redirect_type 1-1 activation_date ${NOW} deactivation_date 2500-01-01T15:53:01.622818Z
 
${response}= POST ${BASE_URL}${REDIRECT_ENDPOINT} json=${payload} headers=${HEADERS} expected_status=400
 
${json} Set Variable ${response.json()}
 
Convert to Dictionary ${json}
 
${ERROR} Get From Dictionary ${json} source
 
Should Contain ${ERROR} A Redirect with the same source and overlapping timespan already exists.
 
 
 
# Clean up
 
Delete Mapping
 
${HEADERS} Create Dictionary Content-Type ${CONTENT_TYPE} Authorization ${TOKEN}
 
${response}= DELETE ${BASE_URL}${MAPPING_ENDPOINT}${MAPPING_ID} headers=${HEADERS} expected_status=204
Loading