Skip to content
Snippets Groups Projects
Verified Commit 5b8d139f authored by Erwan Rouchet's avatar Erwan Rouchet
Browse files

Handle query parameters when retrieving IIIF image information

parent 3f52cbe6
No related branches found
No related tags found
1 merge request!11Handle query parameters when retrieving IIIF image information
Pipeline #202780 passed
......@@ -106,23 +106,32 @@ def test_create_metadata_url(mock_worker):
)
def test_get_image(mock_worker, responses):
responses.add(
responses.GET, "http://imageurl/info.json", json={"@id": "http://imageurl/"}
)
@pytest.mark.parametrize(
("image_id", "expected_url"),
[
("http://imageurl/", "http://imageurl/info.json"),
("http://imageurl/a/b/c", "http://imageurl/a/b/c/info.json"),
# Path parameters should be left as they are
("http://imageurl/a/b;k=v/c", "http://imageurl/a/b;k=v/c/info.json"),
# Query parameters are treated as part of the path to handle non-standard servers
("http://imageurl/a/b/c?k=v", "http://imageurl/a/b/c?k=v/info.json"),
],
)
def test_get_image(mock_worker, responses, image_id, expected_url):
responses.add(responses.GET, expected_url, json={"@id": "http://imageurl/"})
mock_worker.api_client.add_response(
"CreateIIIFInformation",
body={"@id": "http://imageurl/"},
response={"id": "imageid", "url": "http://imageurl", "status": "checked"},
response={"id": "imageid", "url": image_id, "status": "checked"},
)
parser = ManifestParser(mock_worker, BytesIO())
assert parser.get_image("http://imageurl") == {
assert parser.get_image(image_id) == {
"id": "imageid",
"url": "http://imageurl",
"url": image_id,
"status": "checked",
}
responses.assert_call_count("http://imageurl/info.json", 1)
responses.assert_call_count(expected_url, 1)
def test_get_image_check_error(mock_worker, responses):
......
......@@ -255,10 +255,15 @@ class ManifestParser(IIIFParser):
Get or create an Arkindex image from an IIIF image URL.
Returns None if the image could not be created.
"""
parsed_url = urlparse(url)
if not url.endswith("/"):
url += "/"
info_url = urljoin(url, "info.json")
# When the image URL has a query parameter, concatenate strings instead of using `urljoin`
# because some servers do not do any URL rewriting and put the image identifier in a query parameter
info_url = url + "info.json" if parsed_url.query else urljoin(url, "info.json")
try:
payload = self.fetch_image_information(info_url)
except Exception as e:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment