File tree Expand file tree Collapse file tree 3 files changed +41
-6
lines changed
Expand file tree Collapse file tree 3 files changed +41
-6
lines changed Original file line number Diff line number Diff line change 55from 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+
829class UnknownTarget (Exception ):
930 """
1031 Exception raised when Vuforia returns a response with a result code
Original file line number Diff line number Diff line change 11import io
2+ import json
23from urllib .parse import urljoin
4+ from vws .exceptions import MaxNumResultsOutOfRange
35
46import requests
57from 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 )
Original file line number Diff line number Diff line change 44
55import io
66import uuid
7+ import pytest
78
89from vws import VWS , CloudRecoService
10+ from vws .exceptions import MaxNumResultsOutOfRange
911
1012
1113class 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
You can’t perform that action at this time.
0 commit comments