Skip to content

Commit 07112bd

Browse files
committed
Passing simple test
1 parent b3d1e08 commit 07112bd

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

src/vws/_result_codes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
ImageTooLarge,
1212
MetadataTooLarge,
1313
ProjectInactive,
14+
RequestTimeTooSkewed,
1415
TargetNameExist,
1516
TargetStatusNotSuccess,
1617
TargetStatusProcessing,
@@ -43,6 +44,7 @@ def raise_for_result_code(
4344
'InactiveProject': ProjectInactive,
4445
'MetadataTooLarge': MetadataTooLarge,
4546
'ProjectInactive': ProjectInactive,
47+
'RequestTimeTooSkewed': RequestTimeTooSkewed,
4648
'TargetNameExist': TargetNameExist,
4749
'TargetStatusNotSuccess': TargetStatusNotSuccess,
4850
'TargetStatusProcessing': TargetStatusProcessing,

src/vws/exceptions.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,21 @@ def response(self) -> Response:
203203
return self._response
204204

205205

206+
class RequestTimeTooSkewed(Exception):
207+
"""
208+
Exception raised when Vuforia returns a response with a result code
209+
'RequestTimeTooSkewed'.
210+
"""
211+
212+
def __init__(self, response: Response) -> None:
213+
"""
214+
Args:
215+
response: The response to a request to Vuforia.
216+
"""
217+
super().__init__()
218+
self.response = response
219+
220+
206221
class TargetNameExist(Exception):
207222
"""
208223
Exception raised when Vuforia returns a response with a result code

tests/test_exceptions.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
MatchProcessing,
2525
MetadataTooLarge,
2626
ProjectInactive,
27+
RequestTimeTooSkewed,
2728
TargetNameExist,
2829
TargetStatusNotSuccess,
2930
TargetStatusProcessing,
@@ -223,16 +224,12 @@ def test_metadata_too_large(
223224

224225

225226
def test_request_time_too_skewed(vws_client: VWS) -> None:
226-
# TODO Use a flask-based mock so it is not affected by the time freeze
227-
# or :( monkeypatch the time getting thing
228227
vws_max_time_skew = timedelta(minutes=5)
229228
leeway = timedelta(seconds=10)
230229
time_difference_from_now = vws_max_time_skew + leeway
231-
gmt = pytz.timezone('GMT')
232-
with freeze_time(datetime.now(tz=gmt), auto_tick_seconds=1000):
233-
vws_client.get_target_record(target_id='a')
234-
# with pytest.raises(RequestTimeTooSkewed):
235-
# pass
230+
with freeze_time(auto_tick_seconds=time_difference_from_now.seconds):
231+
with pytest.raises(RequestTimeTooSkewed):
232+
vws_client.get_target_record(target_id='a')
236233

237234

238235
def test_authentication_failure(high_quality_image: io.BytesIO) -> None:

0 commit comments

Comments
 (0)