Skip to content

Commit

Permalink
Check for version with size caret, extra tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zimeon committed Nov 9, 2019
1 parent 5c6d9cf commit d5e0abb
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
4 changes: 1 addition & 3 deletions iiif/auth_google.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@

import json
try:
# python3
from urllib.request import urlopen
from urllib.request import Request
from urllib.parse import urlencode
except ImportError:
# fall back to python2
except ImportError: # pragma: no cover # python2
from urllib2 import urlopen
from urllib2 import Request
from urllib import urlencode
Expand Down
2 changes: 1 addition & 1 deletion iiif/flask_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
try: # python3
from urllib.parse import urljoin, quote as urlquote
from urllib.request import parse_keqv_list, parse_http_list
except ImportError: # python2
except ImportError: # pragma: no cover # python2
from urlparse import urljoin
from urllib import quote as urlquote
from urllib2 import parse_keqv_list, parse_http_list
Expand Down
6 changes: 5 additions & 1 deletion iiif/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
try: # python3
from urllib.parse import quote as urlquote
from urllib.parse import unquote as urlunquote
except ImportError: # python2
except ImportError: # pragma: no cover # python2
from urllib import quote as urlquote
from urllib import unquote as urlunquote

Expand Down Expand Up @@ -416,6 +416,10 @@ def parse_size(self, size=None):
self.size_full = False
self.size_wh = (None, None)
if self.size.startswith('^'):
if self.api_version < '3.0':
raise IIIFRequestError(
code=400, parameter="size",
text="Use of caret (^) for upscaling is not supported before API version 3.0")
# as caret can be used with any combination of features
# set caret to true and then remove it to catch further processing
self.size_caret = True
Expand Down
5 changes: 5 additions & 0 deletions tests/test_request_2_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,3 +394,8 @@ def test20_bad_response_codes(self):
self.assertEqual(got_code, code,
"Bad code %s, expected %d, for path %s" %
(str(got_code), code, path))

def test21_caret_not_allowed(self):
"""Caret for upscaling not allowed in 2.1."""
r = IIIFRequest(api_version='2.1')
self.assertRaises(IIIFError, r.parse_size, '^100,100')
10 changes: 10 additions & 0 deletions tests/test_request_3_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@ def test03_parse_size(self):
self.assertFalse(r.size_pct)
self.assertFalse(r.size_bang)
self.assertEqual(r.size_wh, (None, None))
# '^' prefix is new in 3.0
r = IIIFRequest(api_version='3.0')
r.parse_size('^5000,')
self.assertTrue(r.size_caret)
self.assertFalse(r.size_max)
self.assertFalse(r.size_pct)
self.assertFalse(r.size_bang)
self.assertEqual(r.size_wh, (5000, None))

def test04_parse_size_bad(self):
"""Parse size - bad requests."""
Expand All @@ -193,6 +201,8 @@ def test04_parse_size_bad(self):
self.assertRaises(IIIFError, r.parse_size, '!,1')
self.assertRaises(IIIFError, r.parse_size, '0,1')
self.assertRaises(IIIFError, r.parse_size, '2,0')
# full no longer allowed in 3.0
self.assertRaises(IIIFError, r.parse_size, 'full')

def test05_parse_rotation(self):
"""Parse rotation."""
Expand Down

0 comments on commit d5e0abb

Please sign in to comment.