Skip to content

Commit d9a1cc7

Browse files
Merge pull request #1038 from adamtheturtle/authorization-query
Raise results for result codes
2 parents 65c497c + 75b3199 commit d9a1cc7

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/vws/query.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from urllib3.filepost import encode_multipart_formdata
1111

1212
from ._authorization import authorization_header, rfc_1123_date
13+
from ._result_codes import raise_for_result_code
1314

1415

1516
class CloudRecoService:
@@ -80,4 +81,8 @@ def query(self, image: io.BytesIO) -> List[Dict[str, Any]]:
8081
data=content,
8182
)
8283

84+
raise_for_result_code(
85+
response=response,
86+
expected_result_code='Success',
87+
)
8388
return list(response.json()['results'])

tests/test_exceptions.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from PIL import Image
1313
from requests import codes
1414

15-
from vws import VWS
15+
from vws import VWS, CloudRecoService
1616
from vws.exceptions import (
1717
AuthenticationFailure,
1818
BadImage,
@@ -211,7 +211,8 @@ def test_metadata_too_large(
211211
def test_authentication_failure(high_quality_image: io.BytesIO) -> None:
212212
"""
213213
An ``AuthenticationFailure`` exception is raised when the server access key
214-
exists but the server secret key is incorrect.
214+
exists but the server secret key is incorrect, or when a client key is
215+
incorrect.
215216
"""
216217
database = VuforiaDatabase()
217218
with MockVWS() as mock:
@@ -230,6 +231,16 @@ def test_authentication_failure(high_quality_image: io.BytesIO) -> None:
230231

231232
assert exc.value.response.status_code == codes.UNAUTHORIZED
232233

234+
cloud_reco_client = CloudRecoService(
235+
client_access_key=database.client_access_key,
236+
client_secret_key='a',
237+
)
238+
239+
with pytest.raises(AuthenticationFailure) as exc:
240+
cloud_reco_client.query(image=high_quality_image)
241+
242+
assert exc.value.response.status_code == codes.UNAUTHORIZED
243+
233244

234245
def test_target_status_not_success(
235246
vws_client: VWS,

0 commit comments

Comments
 (0)