Skip to content

Commit d7e8478

Browse files
committed
Add test for image too large
1 parent fc8b9eb commit d7e8478

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed

src/vws/exceptions.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,19 @@
22
Custom exceptions for Vuforia errors.
33
"""
44

5+
import requests
56
from requests import Response
67

78

9+
class ConnectionErrorPossiblyImageTooLarge(
10+
requests.exceptions.ConnectionError,
11+
):
12+
"""
13+
Exception raised when a ConnectionError is raised from a query. This has
14+
been seen to happen when the given image is too large.
15+
"""
16+
17+
818
class MatchProcessing(Exception):
919
"""
1020
Exception raised when a query is made with an image which matches a target

src/vws/query.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111

1212
from ._authorization import authorization_header, rfc_1123_date
1313
from ._result_codes import raise_for_result_code
14-
from .exceptions import MatchProcessing, MaxNumResultsOutOfRange
14+
from .exceptions import (
15+
ConnectionErrorPossiblyImageTooLarge,
16+
MatchProcessing,
17+
MaxNumResultsOutOfRange,
18+
)
1519
from .include_target_data import CloudRecoIncludeTargetData
1620

1721

@@ -68,6 +72,8 @@ def query(
6872
which was recently added, updated or deleted and Vuforia
6973
returns an error in this case.
7074
~vws.exceptions.ProjectInactive: The project is inactive.
75+
~vws.exceptions.ConnectionErrorPossiblyImageTooLarge: The given
76+
image is too large.
7177
7278
Returns:
7379
An ordered list of target details of matching targets.
@@ -101,12 +107,15 @@ def query(
101107
'Content-Type': content_type_header,
102108
}
103109

104-
response = requests.request(
105-
method=method,
106-
url=urljoin(base=self._base_vwq_url, url=request_path),
107-
headers=headers,
108-
data=content,
109-
)
110+
try:
111+
response = requests.request(
112+
method=method,
113+
url=urljoin(base=self._base_vwq_url, url=request_path),
114+
headers=headers,
115+
data=content,
116+
)
117+
except requests.exceptions.ConnectionError as exc:
118+
raise ConnectionErrorPossiblyImageTooLarge from exc
110119

111120
if 'Integer out of range' in response.text:
112121
raise MaxNumResultsOutOfRange(response=response)

tests/test_query.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
from mock_vws.database import VuforiaDatabase
1111

1212
from vws import VWS, CloudRecoService
13-
from vws.exceptions import MaxNumResultsOutOfRange
13+
from vws.exceptions import (
14+
ConnectionErrorPossiblyImageTooLarge,
15+
MaxNumResultsOutOfRange,
16+
)
1417
from vws.include_target_data import CloudRecoIncludeTargetData
1518

1619

@@ -48,6 +51,14 @@ def test_match(
4851
[matching_target] = cloud_reco_client.query(image=high_quality_image)
4952
assert matching_target['target_id'] == target_id
5053

54+
def test_too_large(
55+
self,
56+
cloud_reco_client: CloudRecoService,
57+
png_too_large: io.BytesIO,
58+
) -> None:
59+
with pytest.raises(ConnectionErrorPossiblyImageTooLarge):
60+
cloud_reco_client.query(image=png_too_large)
61+
5162

5263
class TestCustomBaseVWQURL:
5364
"""

0 commit comments

Comments
 (0)