diff --git a/requirements.txt b/requirements.txt index 977ec0b475d60f128162b5df3c5996c6c53cc51d..b5e01ce68085a46f56e400c763ec27bf2ac3adec 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,7 +5,7 @@ netbox-docker-plugin == 1.* --extra-index-url https://code.europa.eu/api/v4/projects/662/packages/pypi/simple netbox-cert-plugin == 0.3.* --extra-index-url https://code.europa.eu/api/v4/projects/623/packages/pypi/simple -netbox-rps-plugin == 0.25.* +netbox-rps-plugin == 0.26.* supervisor == 4.2.5 netbox-mac-address-plugin == 1.0.* --extra-index-url https://code.europa.eu/api/v4/projects/921/packages/pypi/simple diff --git a/tests/robot/netbox_rps_plugin/redirect.robot b/tests/robot/netbox_rps_plugin/redirect.robot new file mode 100644 index 0000000000000000000000000000000000000000..245495ca99b653b9025680dece9802d448201459 --- /dev/null +++ b/tests/robot/netbox_rps_plugin/redirect.robot @@ -0,0 +1,132 @@ +*** 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