File tree Expand file tree Collapse file tree 2 files changed +21
-7
lines changed
Expand file tree Collapse file tree 2 files changed +21
-7
lines changed Original file line number Diff line number Diff line change 88from vws .exceptions import MaxNumResultsOutOfRange
99
1010from ._authorization import authorization_header , rfc_1123_date
11+ # TODO this cannot be private...
12+ from .vws import _raise_for_result_code
1113
1214
1315class CloudRecoService :
@@ -74,8 +76,8 @@ def query(
7476 data = content ,
7577 )
7678
77- try :
78- return response . json ()[ 'results' ]
79- except json . decoder . JSONDecodeError :
80- if 'Accepted range is from 1 to 50 (inclusive).' in response . text :
81- raise MaxNumResultsOutOfRange ( response = response )
79+ if 'Accepted range is from 1 to 50 (inclusive).' in response . text :
80+ raise MaxNumResultsOutOfRange ( response = response )
81+
82+ _raise_for_result_code ( response = response , expected_result_code = 'Success' )
83+ return response . json ()[ 'results' ]
Original file line number Diff line number Diff line change 44
55import io
66import uuid
7+ from requests import codes
78
89import pytest
910
1011from vws import VWS , CloudRecoService
11- from vws .exceptions import MaxNumResultsOutOfRange
12+ from vws .exceptions import AuthenticationFailure , MaxNumResultsOutOfRange
1213
1314
1415class TestQuery :
@@ -125,9 +126,20 @@ def test_too_many(
125126 )
126127 assert str (exc .value ) == expected_value
127128
129+ class TestBadCredentials :
130+
131+ def test_bad_credentials (self , high_quality_image : io .BytesIO ):
132+ cloud_reco_client = CloudRecoService (
133+ client_access_key = 'a' ,
134+ client_secret_key = 'a' ,
135+ )
136+ with pytest .raises (AuthenticationFailure ) as exc :
137+ cloud_reco_client .query (image = high_quality_image )
138+
139+ assert exc .value .response .status_code == codes .UNAUTHORIZED
140+
128141
129142# TODO test custom base URL
130- # TODO test bad credentials
131143# TODO test options - include_target_data
132144
133145# TODO do we give an image type? Infer it?
You can’t perform that action at this time.
0 commit comments