Skip to content

Commit

Permalink
Ensuring canvas_id is unique
Browse files Browse the repository at this point in the history
  • Loading branch information
glenrobson authored and Robert Keizer committed May 9, 2024
1 parent ce9073d commit 787bc0c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 4 additions & 2 deletions iiify/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,17 +472,19 @@ def create_manifest3(identifier, domain=None, page=None):

elif mediatype == 'image':
(multiFile, format) = checkMultiItem(metadata)
#print (f"Checking multiFile {multiFile} {format}")
print (f"Checking multiFile {multiFile} {format}")
if multiFile:
# Create multi file manifest
pageCount = 0
for file in metadata['files']:
if file['source'] == "original" and file['format'] == format:
imgId = f"{identifier}/{file['name']}".replace('/','%2f')
imgURL = f"{IMG_SRV}/3/{imgId}"
pageCount += 1

try:
manifest.make_canvas_from_iiif(url=imgURL,
id=f"{URI_PRIFIX}/{identifier}/canvas",
id=f"{URI_PRIFIX}/{identifier}${pageCount}/canvas",
label=f"{file['name']}",
anno_page_id=f"{uri}/annotationPage/1",
anno_id=f"{uri}/annotation/1")
Expand Down
8 changes: 6 additions & 2 deletions tests/test_manifests.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,21 @@ def test_metadata_array(self):
manifest = resp.json
self.assertTrue(len(manifest['summary']['none']) > 1, f"Expected multiple summary values, but got {manifest['summary']['none']}")

def test_multi_file(self):
def test_multi_file_image(self):
resp = self.test_app.get("/iiif/3/arkivkopia.se-lms-G70-48.3/manifest.json")
self.assertEqual(resp.status_code, 200)
manifest = resp.json
self.assertEqual(len(manifest['items']),3, f"Expected three canvases, but got {len(manifest['items'])}")

firstCanvasId = manifest['items'][0]['id']
for i in range(1, len(manifest['items'])):
self.assertNotEqual(manifest['items'][i]['id'], firstCanvasId, 'Canvas Ids need to be unique')

def test_multi_file(self):
resp = self.test_app.get("/iiif/3/st-anthony-relics-01/manifest.json")
self.assertEqual(resp.status_code, 200)
manifest = resp.json
self.assertEqual(len(manifest['items']),5, f"Expected five canvases, but got {len(manifest['items'])}")
self.assertEqual(len(manifest['items']),6, f"Expected five canvases, but got {len(manifest['items'])}")


''' to test:
Expand Down

0 comments on commit 787bc0c

Please sign in to comment.