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

Pass additional properties to AnnotationItem #114

Merged
merged 1 commit into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions iiif_prezi3/helpers/canvas_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class AddImageToCanvas:

def add_image(self, image_url, anno_id=None, anno_page_id=None):
def add_image(self, image_url, anno_id=None, anno_page_id=None, **kwargs):
"""Adds an image to an existing canvas.

Args:
Expand All @@ -18,7 +18,7 @@ def add_image(self, image_url, anno_id=None, anno_page_id=None):
anno_page (iiif-prezi3.skeleton.AnnotationPage): the AnnotationPage with
an Annotation and ResourceItem attached.
"""
body = ResourceItem(id=image_url, type='Image')
body = ResourceItem(id=image_url, type='Image', **kwargs)
annotation = Annotation(id=anno_id, body=body, target=image_url, motivation='painting', type='Annotation')
anno_page = AnnotationPage(id=anno_page_id, type='AnnotationPage', items=[annotation])
if not self.items:
Expand Down
6 changes: 5 additions & 1 deletion tests/test_canvas_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ def setUp(self):
self.canvas = Canvas(id='http://iiif.example.org/prezi/Canvas/0')

def test_add_image(self):
anno_page = self.canvas.add_image('http://iiif.example.org/prezi/Image/0', 'http://iiif.example.org/prezi/Annotation/0')
anno_page = self.canvas.add_image(
'http://iiif.example.org/prezi/Image/0',
'http://iiif.example.org/prezi/Annotation/0',
height=400)
self.assertTrue(isinstance(anno_page, AnnotationPage), '`add_image` should return an AnnotationPage')
self.assertEqual(len(self.canvas.items), 1)
self.assertEqual(anno_page.items[0].id, 'http://iiif.example.org/prezi/Annotation/0')
self.assertEqual(anno_page.items[0].target, 'http://iiif.example.org/prezi/Image/0')
self.assertEqual(anno_page.items[0].dict()["body"]["id"], 'http://iiif.example.org/prezi/Image/0')
self.assertEqual(anno_page.items[0].dict()["body"]["height"], 400)