Skip to content

Commit

Permalink
Init thumbnail tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
markpbaggett committed Dec 4, 2024
1 parent 73a9573 commit aeb6e92
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions tests/test_add_thumbnail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import unittest
from unittest.mock import Mock, patch

from iiif_prezi3 import Manifest


class AddThumbnailTests(unittest.TestCase):

def setUp(self):
self.manifest = Manifest(label={'en': ['Manifest label']})

@patch('iiif_prezi3.helpers.set_hwd_from_iiif.requests.get')
def test_create_thumbnail_from_iiif_v3(self, mockrequest_get):
image_id = 'https://fixtures.iiif.io/other/level0/Glen/photos/gottingen'
image_info_url = f'{image_id}/info.json'

# successful response with dimensions
mockresponse = Mock(status_code=200)
mockrequest_get.return_value = mockresponse
# set mock to return minimal image api response
mockresponse.json.return_value = {
"@context": "http://iiif.io/api/image/3/context.json",
"id": "https://fixtures.iiif.io/other/level0/Glen/photos/gottingen",
"type": "ImageService3",
"protocol": "http://iiif.io/api/image",
"profile": "level0",
"width": 4032,
"height": 3024,
"sizes": [
{
"width": 126,
"height": 95
},
{
"width": 252,
"height": 189
},
{
"width": 504,
"height": 378
},
{
"width": 1008,
"height": 756
},
{
"width": 2016,
"height": 1512
},
{
"width": 4032,
"height": 3024
}
]
}

thumbnail = self.manifest.create_thumbnail_from_iiif(image_info_url)[0]

# check thumbnail matches preferred size
self.assertEqual(thumbnail.height, 378)
self.assertEqual(thumbnail.width, 504)

# check thumbnail id
self.assertEqual(thumbnail.id, "https://fixtures.iiif.io/other/level0/Glen/photos/gottingen/full/504,378/0/default.jpg")

# check thumbnail service
service = thumbnail.service[0]
self.assertEqual(service['profile'], "level0")
self.assertEqual(service['type'], "ImageService3")

0 comments on commit aeb6e92

Please sign in to comment.