Skip to content

Commit c2a5bcb

Browse files
committed
Progress
1 parent 533141a commit c2a5bcb

File tree

3 files changed

+41
-6
lines changed

3 files changed

+41
-6
lines changed

src/vws/exceptions.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,27 @@
55
from requests import Response
66

77

8+
class MaxNumResultsOutOfRange(Exception):
9+
"""
10+
TODO
11+
"""
12+
13+
def __init__(self, response: Response) -> None:
14+
"""
15+
Args:
16+
response: The response to a request to Vuforia.
17+
"""
18+
super().__init__(response.text)
19+
self._response = response
20+
21+
@property
22+
def response(self) -> Response:
23+
"""
24+
The response returned by Vuforia which included this error.
25+
"""
26+
return self._response
27+
28+
829
class UnknownTarget(Exception):
930
"""
1031
Exception raised when Vuforia returns a response with a result code

src/vws/query.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import io
2+
import json
23
from urllib.parse import urljoin
4+
from vws.exceptions import MaxNumResultsOutOfRange
35

46
import requests
57
from urllib3.filepost import encode_multipart_formdata
@@ -71,6 +73,8 @@ def query(
7173
data=content,
7274
)
7375

74-
return response.json()['results']
75-
import pdb; pdb.set_trace()
76-
return response
76+
try:
77+
return response.json()['results']
78+
except json.decoder.JSONDecodeError:
79+
if 'Accepted range is from 1 to 50 (inclusive).' in response.text:
80+
raise MaxNumResultsOutOfRange(response=response)

tests/test_query.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
import io
66
import uuid
7+
import pytest
78

89
from vws import VWS, CloudRecoService
10+
from vws.exceptions import MaxNumResultsOutOfRange
911

1012

1113
class TestQuery:
@@ -112,10 +114,18 @@ def test_too_many(
112114
cloud_reco_client: CloudRecoService,
113115
high_quality_image: io.BytesIO,
114116
) -> None:
115-
matches = cloud_reco_client.query(
116-
image=high_quality_image,
117-
max_num_results=51,
117+
with pytest.raises(MaxNumResultsOutOfRange) as exc:
118+
cloud_reco_client.query(
119+
image=high_quality_image,
120+
max_num_results=51,
121+
)
122+
123+
expected_value = (
124+
"Integer out of range (51) in form data part 'max_result'. "
125+
'Accepted range is from 1 to 50 (inclusive).'
118126
)
127+
assert str(exc.value) == expected_value
128+
119129

120130

121131
# TODO test custom base URL

0 commit comments

Comments
 (0)