Skip to content

Commit

Permalink
ukwa#19 add tests to cover new api parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
ldbiz committed Jun 11, 2023
1 parent e787191 commit a14d1c0
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 56 deletions.
20 changes: 20 additions & 0 deletions tests/website/_api_shared.robot
Original file line number Diff line number Diff line change
@@ -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}



150 changes: 94 additions & 56 deletions tests/website/api.robot
Original file line number Diff line number Diff line change
@@ -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 ***

Expand All @@ -28,134 +15,184 @@ 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

# ---------------------------
# Mementos - WARC
# ---------------------------

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}

Expand All @@ -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

Expand All @@ -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

# ---------------------------
Expand All @@ -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


Expand All @@ -223,21 +260,21 @@ 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

# ---------------------------
# STATS
# ---------------------------

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
Expand All @@ -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

Loading

0 comments on commit a14d1c0

Please sign in to comment.