Skip to content

Commit

Permalink
update the ordering of ImageInfo parameters, and fix tests to explici…
Browse files Browse the repository at this point in the history
…tly specify the parameters they're using
  • Loading branch information
bcail committed Jan 6, 2020
1 parent 66977fe commit 8e13d24
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 31 deletions.
9 changes: 4 additions & 5 deletions loris/img_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,11 @@ class ImageInfo(JP2Extractor):
auth_rules (dict): extra information about authorization [non IIIF]
'''
__slots__ = ('scaleFactors', 'width', 'tiles', 'height',
'profile', 'sizes', 'service',
'attribution', 'logo', 'license', 'auth_rules',
'src_format', 'src_img_fp', 'color_profile_bytes')
__slots__ = ('width', 'height', 'scaleFactors', 'sizes', 'tiles',
'profile', 'service', 'attribution', 'license', 'logo',
'src_img_fp', 'src_format', 'color_profile_bytes', 'auth_rules')

def __init__(self, app=None, src_img_fp="", src_format="", attribution=None, logo=None, license=None, service=None, auth_rules=None):
def __init__(self, app=None, service=None, attribution=None, license=None, logo=None, src_img_fp="", src_format="", auth_rules=None):
self.src_img_fp = src_img_fp
self.src_format = src_format
self.attribution = attribution
Expand Down
6 changes: 3 additions & 3 deletions loris/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def resolve(self, app, ident, base_uri):
source_fp = self.source_file_path(ident)
format_ = self.format_from_ident(ident)
auth_rules = self.get_auth_rules(ident, source_fp)
return ImageInfo(app, source_fp, format_, auth_rules=auth_rules)
return ImageInfo(app=app, src_img_fp=source_fp, src_format=format_, auth_rules=auth_rules)


class ExtensionNormalizingFSResolver(SimpleFSResolver):
Expand Down Expand Up @@ -367,7 +367,7 @@ def resolve(self, app, ident, base_uri):
cached_file_path = self.copy_to_cache(ident)
format_ = self.get_format(cached_file_path, None)
auth_rules = self.get_auth_rules(ident, cached_file_path)
return ImageInfo(app, cached_file_path, format_, auth_rules=auth_rules)
return ImageInfo(app=app, src_img_fp=cached_file_path, src_format=format_, auth_rules=auth_rules)


class TemplateHTTPResolver(SimpleHTTPResolver):
Expand Down Expand Up @@ -549,4 +549,4 @@ def resolve(self, app, ident, base_uri):
cache_fp = self.cache_file_path(ident)
format_ = self.format_from_ident(ident)
auth_rules = self.get_auth_rules(ident, cache_fp)
return ImageInfo(app, cache_fp, format_, auth_rules=auth_rules)
return ImageInfo(app=app, src_img_fp=cache_fp, src_format=format_, auth_rules=auth_rules)
12 changes: 6 additions & 6 deletions tests/authorizer_t.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def setUp(self):
fp = "img/test.png"
fmt = "png"
self.authorizer = NullAuthorizer({})
self.info = ImageInfo(None, fp, fmt)
self.info = ImageInfo(app=None, src_img_fp=fp, src_format=fmt)
self.request = MockRequest()

def test_is_protected(self):
Expand All @@ -69,7 +69,7 @@ def setUp(self):
fp = "img/test.png"
fmt = "png"
self.authorizer = NooneAuthorizer({})
self.info = ImageInfo(None, fp, fmt)
self.info = ImageInfo(app=None, src_img_fp=fp, src_format=fmt)
self.request = MockRequest()

def test_is_protected(self):
Expand All @@ -90,9 +90,9 @@ def setUp(self):
fp = "img/test.png"
fmt = "png"
self.authorizer = SingleDegradingAuthorizer({})
self.badInfo = ImageInfo(None, fp, fmt)
self.badInfo = ImageInfo(app=None, src_img_fp=fp, src_format=fmt)
self.okayIdent = "67352ccc-d1b0-11e1-89ae-279075081939.jp2"
self.okayInfo = ImageInfo(None, "img/%s" % self.okayIdent, "jp2")
self.okayInfo = ImageInfo(app=None, src_img_fp="img/%s" % self.okayIdent, src_format="jp2")
self.request = MockRequest()

def test_is_protected(self):
Expand Down Expand Up @@ -120,9 +120,9 @@ def setUp(self):
{"cookie_secret": b"4rakTQJDyhaYgoew802q78pNnsXR7ClvbYtAF1YC87o=",
"token_secret": b"hyQijpEEe9z1OB9NOkHvmSA4lC1B4lu1n80bKNx0Uz0=",
"salt": b"4rakTQJD4lC1B4lu"})
self.badInfo = ImageInfo(None, fp, fmt)
self.badInfo = ImageInfo(app=None, src_img_fp=fp, src_format=fmt)
self.okayIdent = "67352ccc-d1b0-11e1-89ae-279075081939.jp2"
self.okayInfo = ImageInfo(None, "img/%s" % self.okayIdent, "jp2")
self.okayInfo = ImageInfo(app=None, src_img_fp="img/%s" % self.okayIdent, src_format="jp2")

self.origin = "localhost"
# role to get access is "test"
Expand Down
24 changes: 12 additions & 12 deletions tests/img_info_t.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_color_jp2_info_from_image(self):

#test that sizeAboveFull isn't in profile if max_size_above_full is > 0 and <= 100
self.app.max_size_above_full = 80
info = img_info.ImageInfo(self.app, fp, fmt)
info = img_info.ImageInfo(app=self.app, src_img_fp=fp, src_format=fmt)

self.assertEqual(info.width, self.test_jp2_color_dims[0])
self.assertEqual(info.height, self.test_jp2_color_dims[1])
Expand All @@ -62,7 +62,7 @@ def test_color_jp2_info_from_image(self):
self.assertEqual(info.sizes, self.test_jp2_color_sizes)

self.app.max_size_above_full = 0
info = img_info.ImageInfo(self.app, fp, fmt)
info = img_info.ImageInfo(app=self.app, src_img_fp=fp, src_format=fmt)
self.assertTrue('sizeAboveFull' in info.profile.description['supports'])
self.app.max_size_above_full = 200

Expand All @@ -73,7 +73,7 @@ def test_precinct_jp2_tiles_from_image(self):
ident = self.test_jp2_with_precincts_id
uri = self.test_jp2_with_precincts_uri

info = img_info.ImageInfo(self.app, fp, fmt)
info = img_info.ImageInfo(app=self.app, src_img_fp=fp, src_format=fmt)

self.assertEqual(info.tiles, self.test_jp2_with_precincts_tiles)
self.assertEqual(info.sizes, self.test_jp2_with_precincts_sizes)
Expand All @@ -85,7 +85,7 @@ def test_extract_icc_profile_from_jp2(self):
uri = self.test_jp2_with_embedded_profile_uri
profile_copy_fp = self.test_jp2_embedded_profile_copy_fp

info = img_info.ImageInfo(self.app, fp, fmt)
info = img_info.ImageInfo(app=self.app, src_img_fp=fp, src_format=fmt)

with open(self.test_jp2_embedded_profile_copy_fp, 'rb') as fixture_bytes:
self.assertEqual(info.color_profile_bytes, fixture_bytes.read())
Expand All @@ -96,7 +96,7 @@ def test_no_embedded_profile_info_color_profile_bytes_is_None(self):
ident = self.test_jp2_color_id
uri = self.test_jp2_color_uri

info = img_info.ImageInfo(self.app, fp, fmt)
info = img_info.ImageInfo(app=self.app, src_img_fp=fp, src_format=fmt)
self.assertEqual(info.color_profile_bytes, None)

def test_gray_jp2_info_from_image(self):
Expand All @@ -123,7 +123,7 @@ def test_gray_jp2_info_from_image(self):
}
]

info = img_info.ImageInfo(self.app, fp, fmt)
info = img_info.ImageInfo(app=self.app, src_img_fp=fp, src_format=fmt)

self.assertEqual(info.width, self.test_jp2_gray_dims[0])
self.assertEqual(info.height, self.test_jp2_gray_dims[1])
Expand All @@ -138,7 +138,7 @@ def test_info_from_jpg_marked_as_jp2(self):
ident = '01%2f03%2f0001.jpg'
uri = '%s/%s' % (self.URI_BASE, ident)
with self.assertRaises(loris_exception.ImageInfoException) as cm:
img_info.ImageInfo(self.app, fp, fmt)
img_info.ImageInfo(app=self.app, src_img_fp=fp, src_format=fmt)
self.assertEqual(str(cm.exception), 'Invalid JP2 file')

def test_info_from_invalid_src_format(self):
Expand All @@ -148,7 +148,7 @@ def test_info_from_invalid_src_format(self):
uri = '%s/%s' % (self.URI_BASE, ident)
error_message = "Didn\'t get a source format, or at least one we recognize ('invalid_format')."
with self.assertRaises(loris_exception.ImageInfoException) as cm:
img_info.ImageInfo(self.app, fp, fmt)
img_info.ImageInfo(app=self.app, src_img_fp=fp, src_format=fmt)
self.assertEqual(str(cm.exception), error_message)

def test_jpeg_info_from_image(self):
Expand All @@ -157,7 +157,7 @@ def test_jpeg_info_from_image(self):
ident = self.test_jpeg_id
uri = self.test_jpeg_uri

info = img_info.ImageInfo(self.app, fp, fmt)
info = img_info.ImageInfo(app=self.app, src_img_fp=fp, src_format=fmt)

profile = ["http://iiif.io/api/image/2/level2.json", {
"formats": [ "jpg", "png", "gif", "webp", "tif" ],
Expand Down Expand Up @@ -185,7 +185,7 @@ def test_png_info_from_image(self):
ident = self.test_png_id
uri = self.test_png_uri

info = img_info.ImageInfo(self.app, fp, fmt)
info = img_info.ImageInfo(app=self.app, src_img_fp=fp, src_format=fmt)

profile = ["http://iiif.io/api/image/2/level2.json", {
"formats": [ "jpg", "png", "gif", "webp", "tif" ],
Expand Down Expand Up @@ -214,7 +214,7 @@ def test_tiff_info_from_image(self):
ident = self.test_tiff_id
uri = self.test_tiff_uri

info = img_info.ImageInfo(self.app, fp, fmt)
info = img_info.ImageInfo(app=self.app, src_img_fp=fp, src_format=fmt)

profile = ["http://iiif.io/api/image/2/level2.json", {
"formats": [ "jpg", "png", "gif", "webp", "tif" ],
Expand Down Expand Up @@ -437,7 +437,7 @@ def _cache_with_ident(self):
"""
cache = img_info.InfoCache(root=self.SRC_IMAGE_CACHE)

info = img_info.ImageInfo(self.app, self.test_jp2_color_fp, self.test_jp2_color_fmt)
info = img_info.ImageInfo(app=self.app, src_img_fp=self.test_jp2_color_fp, src_format=self.test_jp2_color_fmt)

cache[self.test_jp2_color_id] = info
return (cache, self.test_jp2_color_id)
Expand Down
4 changes: 2 additions & 2 deletions tests/img_t.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_request_path(self, args, request_path):
(('id4', 'full', '!80,20', '30', 'default', 'jpg'), False),
])
def test_is_canonical(self, args, is_canonical):
info = img_info.ImageInfo(None)
info = img_info.ImageInfo()
info.width = 100
info.height = 100
request = img.ImageRequest(*args)
Expand Down Expand Up @@ -84,7 +84,7 @@ def test_canonical_requests_cache_at_canonical_path(self):

def test_cache_dir_already_exists(self):
ident = 'id1'
image_info = img_info.ImageInfo(None)
image_info = img_info.ImageInfo()
image_info.width = 100
image_info.height = 100
image_request = img.ImageRequest(ident, 'full', 'full', '0', 'default', 'jpg')
Expand Down
6 changes: 3 additions & 3 deletions tests/parameters_t.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

def build_image_info(width=100, height=100):
"""Produces an ``ImageInfo`` object of the given dimensions."""
info = img_info.ImageInfo(None)
info = img_info.ImageInfo()
info.width = width
info.height = height
return info
Expand All @@ -28,7 +28,7 @@ def _get_info_long_y(self):
fmt = self.test_jp2_color_fmt
ident = self.test_jp2_color_id
uri = self.test_jp2_color_uri
ii = img_info.ImageInfo(self.app, fp, fmt)
ii = img_info.ImageInfo(app=self.app, src_img_fp=fp, src_format=fmt)
return ii

def _get_info_long_x(self):
Expand All @@ -37,7 +37,7 @@ def _get_info_long_x(self):
fmt = self.test_jpeg_fmt
ident = self.test_jpeg_id
uri = self.test_jpeg_uri
ii = img_info.ImageInfo(self.app, fp, fmt)
ii = img_info.ImageInfo(app=self.app, src_img_fp=fp, src_format=fmt)
return ii

class TestRegionParameter(_ParameterTest):
Expand Down

0 comments on commit 8e13d24

Please sign in to comment.