diff --git a/tests/website/_api_shared.robot b/tests/website/_api_shared.robot new file mode 100644 index 0000000..ea14cfb --- /dev/null +++ b/tests/website/_api_shared.robot @@ -0,0 +1,20 @@ +*** Settings *** +Documentation A resource file with reusable keywords and variables. +Library RequestsLibrary +Library Collections +Library String + + + +*** Variables *** +#reading room only/restricted access +${RRO_URL} %{TEST_RRO_URL=http://bbc.co.uk} +${TEST_URL} %{TEST_URL=http://portico.bl.uk} +${TEST_TIMESTAMP} %{TEST_TIMESTAMP=19950418155600} +${TEST_FULL_TIMESTAMP} %{TEST_FULL_TIMESTAMP=1995-04-18T15:56:00Z} +${TEST_APPROX_TIMESTAMP} %{TEST_TIMESTAMP=19950101000000} +${TEST_VALID_COLLECTIONID} %{TEST_VALID_COLLECTIONID=4388} +${TEST_INVALID_COLLECTIONID} %{TEST_INVALID_COLLECTIONID=999999} + + + diff --git a/tests/website/api.robot b/tests/website/api.robot index 0187a16..d67cd12 100644 --- a/tests/website/api.robot +++ b/tests/website/api.robot @@ -1,21 +1,8 @@ - *** Settings *** -Library Collections -Library RequestsLibrary -Library String - +Resource _api_shared.robot -*** Variables *** -#reading room only/restricted access -${RRO_URL} %{TEST_RRO_URL=http://bbc.co.uk} -${TEST_URL} %{TEST_URL=http://portico.bl.uk} -${TEST_TIMESTAMP} %{TEST_TIMESTAMP=19950418155600} -${TEST_FULL_TIMESTAMP} %{TEST_FULL_TIMESTAMP=1995-04-18T15:56:00Z} -${TEST_APPROX_TIMESTAMP} %{TEST_TIMESTAMP=19950101000000} -${TEST_VALID_COLLECTIONID} %{TEST_VALID_COLLECTIONID=4388} -${TEST_INVALID_COLLECTIONID} %{TEST_INVALID_COLLECTIONID=999999} *** Keywords *** @@ -28,108 +15,158 @@ Generate PWID [Arguments] ${timestamp} ${url} *** Test Cases *** Check the API documentation page is there - ${response}= GET %{HOST}/api expected_status=200 + [Tags] Base + ${response}= GET %{HOST}/docs expected_status=200 Should Contain ${response.text} UK Web Archive API Should Contain ${response.text} swagger-ui + + # --------------------------- # Mementos - CDX query # --------------------------- Query CDX API, no URL - ${response}= GET %{HOST}/api/query/lookup params=query=ciao expected_status=422 + [Tags] URL + ${response}= GET %{HOST}/mementos/cdx params=query=ciao expected_status=422 Should Contain ${response.text} field required Query CDX API, bad URL - ${response}= GET %{HOST}/api/query/lookup params=url=notanykindofmatchhere expected_status=422 + [Tags] URL + ${response}= GET %{HOST}/mementos/cdx params=url=notanykindofmatchhere expected_status=422 Should Contain ${response.text} invalid or missing URL scheme Query CDX API, valid URL, no hits - ${response}= GET %{HOST}/api/query/lookup params=url=http://no.such.url expected_status=200 + [Tags] URL + ${response}= GET %{HOST}/mementos/cdx params=url=http://no.such.url expected_status=200 Should Be Equal ${response.text} ${EMPTY} Query CDX API, TEST_URL - ${response}= GET %{HOST}/api/query/lookup params=url=${TEST_URL} expected_status=200 + [Tags] URL + ${response}= GET %{HOST}/mementos/cdx params=url=${TEST_URL} expected_status=200 Should Contain ${response.text} ${TEST_URL} Query CDX API, Invalid matchType - ${response}= GET %{HOST}/api/query/lookup params=url=${TEST_URL}&matchType=foobar expected_status=422 + ${response}= GET %{HOST}/mementos/cdx params=url=${TEST_URL}&matchType=foobar expected_status=422 Should Contain ${response.text} value is not a valid enumeration member Query CDX API, Valid matchType exact - ${response}= GET %{HOST}/api/query/lookup params=url=${TEST_URL}&matchType=exact expected_status=200 + ${response}= GET %{HOST}/mementos/cdx params=url=${TEST_URL}&matchType=exact expected_status=200 Should Contain ${response.text} ${TEST_URL} Query CDX API, Valid matchType prefix - ${response}= GET %{HOST}/api/query/lookup params=url=${TEST_URL}&matchType=prefix&limit=10 expected_status=200 + ${response}= GET %{HOST}/mementos/cdx params=url=${TEST_URL}&matchType=prefix&limit=10 expected_status=200 Should Contain ${response.text} ${TEST_URL} Query CDX API, Valid matchType host - ${response}= GET %{HOST}/api/query/lookup params=url=${TEST_URL}&matchType=host&limit=10 expected_status=200 + ${response}= GET %{HOST}/mementos/cdx params=url=${TEST_URL}&matchType=host&limit=10 expected_status=200 Should Contain ${response.text} ${TEST_URL} Query CDX API, Valid matchType domain - ${response}= GET %{HOST}/api/query/lookup params=url=${TEST_URL}&matchType=domain&limit=10 expected_status=200 + ${response}= GET %{HOST}/mementos/cdx params=url=${TEST_URL}&matchType=domain&limit=10 expected_status=200 Should Contain ${response.text} ${TEST_URL} Query CDX API, Valid matchType range - ${response}= GET %{HOST}/api/query/lookup params=url=${TEST_URL}&matchType=range&limit=10 expected_status=200 + ${response}= GET %{HOST}/mementos/cdx params=url=${TEST_URL}&matchType=range&limit=10 expected_status=200 Should Contain ${response.text} ${TEST_URL} Query CDX API, Invalid sort - ${response}= GET %{HOST}/api/query/lookup params=url=${TEST_URL}&sort=foobar expected_status=422 + ${response}= GET %{HOST}/mementos/cdx params=url=${TEST_URL}&sort=foobar expected_status=422 Should Contain ${response.text} value is not a valid enumeration member Query CDX API, Valid sort default - ${response}= GET %{HOST}/api/query/lookup params=url=${TEST_URL}&sort=default expected_status=200 + ${response}= GET %{HOST}/mementos/cdx params=url=${TEST_URL}&sort=default expected_status=200 Should Contain ${response.text} ${TEST_URL} Query CDX API, Valid sort closest - ${response}= GET %{HOST}/api/query/lookup params=url=${TEST_URL}&sort=closest expected_status=200 + ${response}= GET %{HOST}/mementos/cdx params=url=${TEST_URL}&sort=closest expected_status=200 Should Contain ${response.text} ${TEST_URL} Query CDX API, Valid sort reverse - ${response}= GET %{HOST}/api/query/lookup params=url=${TEST_URL}&sort=reverse expected_status=200 + ${response}= GET %{HOST}/mementos/cdx params=url=${TEST_URL}&sort=reverse expected_status=200 Should Contain ${response.text} ${TEST_URL} Query CDX API, Valid combination - ${response}= GET %{HOST}/api/query/lookup params=url=${TEST_URL}&sort=reverse&matchType=exact expected_status=200 + ${response}= GET %{HOST}/mementos/cdx params=url=${TEST_URL}&sort=reverse&matchType=exact expected_status=200 Should Contain ${response.text} ${TEST_URL} Query CDX API, Invalid combination - ${response}= GET %{HOST}/api/query/lookup params=url=${TEST_URL}&sort=reverse&matchType=domain expected_status=200 + ${response}= GET %{HOST}/mementos/cdx params=url=${TEST_URL}&sort=reverse&matchType=domain expected_status=200 Should Contain ${response.text} IllegalArgumentException +Valid Closest Param + [Tags] Closest + ${response}= GET %{HOST}/mementos/cdx params=url=${TEST_URL}&sort=closest&closest=${TEST_TIMESTAMP} expected_status=200 + +Invalid Closest Sort Param + [Tags] Closest + ${response}= GET %{HOST}/mementos/cdx params=url=${TEST_URL}&sort=default&closest=${TEST_TIMESTAMP} expected_status=400 + Should Match ${response.content.decode("utf-8")} \{"detail":"Closest Sort required for Closest Timestamp."\} + +Valid Output Type - CDX + [Tags] OutputType + ${response}= GET %{HOST}/mementos/cdx params=url=${TEST_URL}&output=cdx expected_status=200 + Should Contain ${response.headers['Content-Type']} text/plain + +Valid Output Type - JSON + [Tags] OutputType + ${response}= GET %{HOST}/mementos/cdx params=url=${TEST_URL}&output=json expected_status=200 + Should Contain ${response.headers['Content-Type']} application/json + +Invalid Output Type + [Tags] OutputType + ${response}= GET %{HOST}/mementos/cdx params=url=${TEST_URL}&output=xml expected_status=422 + +Valid From Date + [Tags] FromParameter + ${response}= GET %{HOST}/mementos/cdx params=url=${TEST_URL}&from=20220101 expected_status=200 + +Invalid From Date + [Tags] FromParameter + ${response}= GET %{HOST}/mementos/cdx params=url=${TEST_URL}&from=invalid_date expected_status=422 + +Valid To Date + [Tags] ToParameter + ${response}= GET %{HOST}/mementos/cdx params=url=${TEST_URL}&to=20220101 expected_status=200 + +Invalid To Date + [Tags] ToParameter + ${response}= GET %{HOST}/mementos/cdx params=url=${TEST_URL}&to=invalid_date expected_status=422 + +# Collapse Tests in Template File + + + # --------------------------- # Mementos - Resolve # --------------------------- Query Resolve, Valid, No Redirects - ${response}= GET %{HOST}/api/mementos/resolve/${TEST_TIMESTAMP}/${TEST_URL} expected_status=303 allow_redirects=${False} + ${response}= GET %{HOST}/mementos/resolve/${TEST_TIMESTAMP}/${TEST_URL} expected_status=303 allow_redirects=${False} Should Be Equal ${response.text} ${EMPTY} Query Resolve, Valid - ${response}= GET %{HOST}/api/query/resolve/${TEST_TIMESTAMP}/${TEST_URL} expected_status=200 + ${response}= GET %{HOST}/mementos/resolve/${TEST_TIMESTAMP}/${TEST_URL} expected_status=200 Should Contain ${response.text} ${TEST_URL} Query Resolve, Invalid Timestamp - ${response}= GET %{HOST}/api/query/resolve/foobar/${TEST_URL} expected_status=422 + ${response}= GET %{HOST}/mementos/resolve/foobar/${TEST_URL} expected_status=422 Should Contain ${response.text} ensure this value has at least 14 characters Query Resolve, Invalid URL - ${response}= GET %{HOST}/api/query/resolve/${TEST_TIMESTAMP}/foobar expected_status=422 + ${response}= GET %{HOST}/mementos/resolve/${TEST_TIMESTAMP}/foobar expected_status=422 Should Contain ${response.text} invalid or missing URL scheme Query Resolve, Valid URL, No Matches - ${response}= GET %{HOST}/api/query/resolve/${TEST_TIMESTAMP}/https://no.such.url expected_status=404 + ${response}= GET %{HOST}/mementos/resolve/${TEST_TIMESTAMP}/https://no.such.url expected_status=404 Should Contain ${response.text} Not Found Query Resolve, Invalid Timestamp, No Redirects - ${response}= GET %{HOST}/api/mementos/resolve/foobar/${TEST_URL} expected_status=422 allow_redirects=${False} + ${response}= GET %{HOST}/mementos/resolve/foobar/${TEST_URL} expected_status=422 allow_redirects=${False} Should Contain ${response.text} ensure this value has at least 14 characters Query Resolve, Invalid URL, No Redirects - ${response}= GET %{HOST}/api/mementos/resolve/${TEST_TIMESTAMP}/foobar expected_status=422 allow_redirects=${False} + ${response}= GET %{HOST}/mementos/resolve/${TEST_TIMESTAMP}/foobar expected_status=422 allow_redirects=${False} Should Contain ${response.text} invalid or missing URL scheme # --------------------------- @@ -137,25 +174,25 @@ Query Resolve, Invalid URL, No Redirects # --------------------------- Query WARC, Invalid Timestamp - ${response}= GET %{HOST}/api/query/warc/foobar/${TEST_URL} expected_status=422 + ${response}= GET %{HOST}/mementos/warc/foobar/${TEST_URL} expected_status=422 Should Contain ${response.text} ensure this value has at least 14 characters Query WARC, Invalid URL - ${response}= GET %{HOST}/api/query/warc/${TEST_TIMESTAMP}/foobar expected_status=422 + ${response}= GET %{HOST}/mementos/warc/${TEST_TIMESTAMP}/foobar expected_status=422 Should Contain ${response.text} invalid or missing URL scheme Query WARC, Valid URL, No Records - ${response}= GET %{HOST}/api/query/warc/${TEST_TIMESTAMP}/http://no.such.url expected_status=404 + ${response}= GET %{HOST}/mementos/warc/${TEST_TIMESTAMP}/http://no.such.url expected_status=404 Should Contain ${response.text} Not Found Query WARC, Valid URL, Timestamp Mismatch Skip # Should redirect to exact timestamp, but not implemented yet. - ${response}= GET %{HOST}/api/mementos/warc/${TEST_APPROX_TIMESTAMP}/${TEST_URL} expected_status=303 allow_redirects=${False} + ${response}= GET %{HOST}/mementos/warc/${TEST_APPROX_TIMESTAMP}/${TEST_URL} expected_status=303 allow_redirects=${False} Should Be Equal ${response.text} ${EMPTY} Should Contain ${response.headers['location']} ${TEST_TIMESTAMP} Query WARC, Valid - ${response}= GET %{HOST}/api/query/warc/${TEST_TIMESTAMP}/${TEST_URL} expected_status=200 + ${response}= GET %{HOST}/mementos/warc/${TEST_TIMESTAMP}/${TEST_URL} expected_status=200 Should Contain ${response.text} WARC-Target-URI: ${TEST_URL} Should Contain ${response.text} ${TEST_URL} @@ -164,13 +201,13 @@ Query WARC, Valid # --------------------------- Query IIIF Helper, No Redirects - ${response}= GET %{HOST}/api/mementos/screenshot/${TEST_TIMESTAMP}/${TEST_URL} expected_status=303 allow_redirects=${False} + ${response}= GET %{HOST}/mementos/screenshot/${TEST_TIMESTAMP}/${TEST_URL} expected_status=303 allow_redirects=${False} Should Contain ${response.headers['location']} /iiif/2/ Should Contain ${response.headers['location']} default.png Should Be Equal ${response.text} ${EMPTY} Query IIIF Helper, Allow Redirect To Image - ${response}= GET %{HOST}/api/iiif/helper/${TEST_TIMESTAMP}/${TEST_URL} expected_status=200 + ${response}= GET %{HOST}/iiif/helper/${TEST_TIMESTAMP}/${TEST_URL} expected_status=200 Should Be Equal ${response.headers['content-type']} image/png Should Contain ${response.content[1:4].decode('utf-8')} PNG @@ -179,17 +216,17 @@ Query IIIF Helper, Allow Redirect To Image # --------------------------- Query IIIF Helper, Invalid URL - ${response}= GET %{HOST}/api/iiif/helper/${TEST_TIMESTAMP}/foobar expected_status=422 + ${response}= GET %{HOST}/iiif/helper/${TEST_TIMESTAMP}/foobar expected_status=422 Should Contain ${response.text} invalid or missing URL scheme Query IIIF Helper, URL with no records - ${response}= GET %{HOST}/api/iiif/helper/${TEST_TIMESTAMP}/http://no.such.url expected_status=404 + ${response}= GET %{HOST}/iiif/helper/${TEST_TIMESTAMP}/http://no.such.url expected_status=404 Should Contain ${response.text} Not Found # Reading-room-only test cases: Query IIIF Helper, Reading Room Only - ${response}= GET %{HOST}/api/iiif/helper/${TEST_TIMESTAMP}/${RRO_URL} expected_status=451 + ${response}= GET %{HOST}/iiif/helper/${TEST_TIMESTAMP}/${RRO_URL} expected_status=451 Should Contain ${response.text} Unavailable For Legal Reasons # --------------------------- @@ -198,22 +235,22 @@ Query IIIF Helper, Reading Room Only Query IIIF Info, Valid PWID But Invalid URL ${pwid}= Generate PWID ${TEST_FULL_TIMESTAMP} foobar - ${response}= GET %{HOST}/api/iiif/2/${pwid}/0,0,1280,1024/200,125/0/default.png expected_status=404 + ${response}= GET %{HOST}/iiif/2/${pwid}/0,0,1280,1024/200,125/0/default.png expected_status=404 Should Contain ${response.text} Not Found Query IIIF Info, PWID with no records ${pwid}= Generate PWID ${TEST_FULL_TIMESTAMP} http://no.such.url - ${response}= GET %{HOST}/api/iiif/2/${pwid}/0,0,1280,1024/200,125/0/default.png expected_status=404 + ${response}= GET %{HOST}/iiif/2/${pwid}/0,0,1280,1024/200,125/0/default.png expected_status=404 Should Contain ${response.text} Not Found Query IIIF Info, Valid URL - ${response}= GET %{HOST}/api/iiif/2/urn:pwid:webarchive.org.uk:${TEST_FULL_TIMESTAMP}:page:${TEST_URL}/info.json - Should Contain ${response.text} iiif.io/api/image/2/context.json + ${response}= GET %{HOST}/iiif/2/urn:pwid:webarchive.org.uk:${TEST_FULL_TIMESTAMP}:page:${TEST_URL}/info.json + Should Contain ${response.text} iiif.io/image/2/context.json # Reading-room-only test cases: Query IIIF Info, Reading Room Only - ${response}= GET %{HOST}/api/iiif/2/urn:pwid:webarchive.org.uk:${TEST_FULL_TIMESTAMP}:page:${RRO_URL}/info.json expected_status=451 + ${response}= GET %{HOST}/iiif/2/urn:pwid:webarchive.org.uk:${TEST_FULL_TIMESTAMP}:page:${RRO_URL}/info.json expected_status=451 Should Contain ${response.text} Unavailable For Legal Reasons @@ -223,13 +260,13 @@ Query IIIF Info, Reading Room Only Query IIIF Image ${pwid}= Generate PWID ${TEST_FULL_TIMESTAMP} ${TEST_URL} - ${response}= GET %{HOST}/api/iiif/2/${pwid}/0,0,1280,1024/200,125/0/default.png expected_status=200 + ${response}= GET %{HOST}/iiif/2/${pwid}/0,0,1280,1024/200,125/0/default.png expected_status=200 # Reading-room-only test cases: Query IIIF Image, Reading Room Only ${pwid}= Generate PWID ${TEST_FULL_TIMESTAMP} ${RRO_URL} - ${response}= GET %{HOST}/api/iiif/2/${pwid}/0,0,1280,1024/200,125/0/default.png expected_status=451 + ${response}= GET %{HOST}/iiif/2/${pwid}/0,0,1280,1024/200,125/0/default.png expected_status=451 Should Contain ${response.text} Unavailable For Legal Reasons # --------------------------- @@ -237,7 +274,7 @@ Query IIIF Image, Reading Room Only # --------------------------- Query Stats - ${response}= GET %{HOST}/api/stats/crawl/recent-activity + ${response}= GET %{HOST}/stats/crawl/recent-activity Should Contain ${response.text} hosts Should Contain ${response.text} stats Should Contain ${response.text} first_timestamp @@ -256,3 +293,4 @@ Query Collection API, Valid Collection ID Query Collection API, Invalid Collection ID ${response}= GET %{HOST}/download/${TEST_INVALID_COLLECTIONID} expected_status=404 + diff --git a/tests/website/api_collapse.robot b/tests/website/api_collapse.robot new file mode 100644 index 0000000..3cdeb38 --- /dev/null +++ b/tests/website/api_collapse.robot @@ -0,0 +1,38 @@ +# Testing same UI as api.robot but separate file for different testing structure (template style) to reduce duplication for the Collapse param testing + + +*** Settings *** +Resource _api_shared.robot + +Test Template Run CollapseFirstAndLast Tests + + +*** Keywords *** + +Run CollapseFirstAndLast Tests + [Arguments] ${invalid_value} ${valid_value} ${default_value} + ${invalid_first_response}= GET %{HOST}/mementos/cdx params=url=${TEST_URL}&collapseToFirst=${invalid_value} expected_status=422 + ${valid_first_response}= GET %{HOST}/mementos/cdx params=url=${TEST_URL}&collapseToFirst=${valid_value} expected_status=200 + ${valid_first_default}= GET %{HOST}/mementos/cdx params=url=${TEST_URL}&collapseToLast=${default_value} expected_status=200 + ${invalid_last_response}= GET %{HOST}/mementos/cdx params=url=${TEST_URL}&collapseToLast=${invalid_value} expected_status=422 + ${valid_last_response}= GET %{HOST}/mementos/cdx params=url=${TEST_URL}&collapseToLast=${valid_value} expected_status=200 + ${valid_last_default}= GET %{HOST}/mementos/cdx params=url=${TEST_URL}&collapseToLast=${default_value} expected_status=200 + + +*** Test Cases *** + +# ---- Collapse First and Last ---- +# Field Invalid Valid Default +CollapseFirstAndLast urlkey urlkey:100 urlkey:10 urlkey +CollapseFirstAndLast mimetype mimetype:100 mimetype:5 mimetype +CollapseFirstAndLast digest digest:41 digest:5 digest +CollapseFirstAndLast timestamp timestamp:15 timestamp:5 timestamp +CollapseFirstAndLast statuscode statuscode:4 statuscode:1 statuscode +CollapseFirstAndLast length length:13 length:10 length +CollapseFirstAndLast offset offset:13 offset:10 offset +CollapseFirstAndLast filename filename:100 filename:10 filename +CollapseFirstAndLast redirecturl redirecturl:100 redirecturl:10 redirecturl +CollapseFirstAndLast original original:100 original:10 original +CollapseFirstAndLast robotflags robotflags:10 robotflags:1 robotflags + +