Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resources: update files test #1945

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions tests/resources/test_iiif_image_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def publish_record_with_images(
):
"""A record with files."""
record["files"]["enabled"] = True

if restricted_files:
record["access"]["files"] = "restricted"

Expand All @@ -29,23 +30,30 @@ def publish_record_with_images(
res = client.post(
f"/records/{id_}/draft/files", headers=headers, json=[{"key": file_id}]
)

links = res.json["entries"][0]["links"]
# Upload a file
image_file = BytesIO()
image = Image.new("RGBA", (1280, 1024), (255, 0, 0, 0))
image.save(image_file, "png")
image_file.seek(0)
res = client.put(
f"/records/{id_}/draft/files/{file_id}/content",
res1 = client.put(
links["content"].split("/api", 1)[
-1
], # Removes the base URL and keeps only the API path
headers={"content-type": "application/octet-stream"},
data=image_file,
)

# Commit the file
res = client.post(f"/records/{id_}/draft/files/{file_id}/commit", headers=headers)
res2 = client.post(
links["commit"].split("/api", 1)[
-1
], # Removes the base URL and keeps only the API path
headers=headers,
)

# Publish the record
res = client.post(f"/records/{id_}/draft/actions/publish", headers=headers)
res3 = client.post(f"/records/{id_}/draft/actions/publish", headers=headers)

return id_

Expand Down Expand Up @@ -94,12 +102,14 @@ def test_iiif_base(
== f"https://127.0.0.1:5000/api/iiif/record:{recid}:{file_id}/info.json"
)

## Testing with filename with a slash ##
## Testing with filename with a slash and a "#" ##

file_id = "test/image.png"
encoded_file_id = quote(file_id, safe="")
file_id = "test/#image.png"
encoded_file_id = "test%2F%23image.png"
recid = publish_record_with_images(client, file_id, minimal_record, headers)
response = client.get(f"/iiif/record:{recid}:{file_id}")

response = client.get(f"/iiif/record:{recid}:{encoded_file_id}")

assert response.status_code == 301
assert (
response.json["location"]
Expand Down Expand Up @@ -130,12 +140,12 @@ def test_iiif_info(
)
)

## Testing with filename with a slash ##
## Testing with filename with a slash and a "#" ##

file_id = "test/image.png"
encoded_file_id = quote(file_id, safe="")
file_id = "test/#image.png"
encoded_file_id = "test%2F%23image.png"
recid = publish_record_with_images(client, file_id, minimal_record, headers)
response = client.get(f"/iiif/record:{recid}:{file_id}/info.json")
response = client.get(f"/iiif/record:{recid}:{encoded_file_id}/info.json")
assert response.status_code == 200
assert response.json == {
"@context": "http://iiif.io/api/image/2/context.json",
Expand Down
Loading