|
4 | 4 |
|
5 | 5 | import io |
6 | 6 | import random |
7 | | -from datetime import datetime, timedelta |
8 | 7 |
|
9 | 8 | import pytest |
10 | | -import pytz |
| 9 | +from freezegun import freeze_time |
11 | 10 | from mock_vws import MockVWS |
12 | 11 | from mock_vws.database import VuforiaDatabase |
13 | 12 | from mock_vws.states import States |
14 | 13 | from PIL import Image |
15 | 14 | from requests import codes |
16 | 15 |
|
17 | | -from freezegun import freeze_time |
18 | 16 | from vws import VWS, CloudRecoService |
19 | 17 | from vws.exceptions import ( |
20 | 18 | AuthenticationFailure, |
@@ -224,10 +222,21 @@ def test_metadata_too_large( |
224 | 222 |
|
225 | 223 |
|
226 | 224 | def test_request_time_too_skewed(vws_client: VWS) -> None: |
227 | | - vws_max_time_skew = timedelta(minutes=5) |
228 | | - leeway = timedelta(seconds=10) |
| 225 | + """ |
| 226 | + A ``RequestTimeTooSkewed`` exception is raised when the request time is |
| 227 | + more than five minutes different from the server time. |
| 228 | + """ |
| 229 | + vws_max_time_skew = 60 * 5 |
| 230 | + leeway = 10 |
229 | 231 | time_difference_from_now = vws_max_time_skew + leeway |
230 | | - with freeze_time(auto_tick_seconds=time_difference_from_now.seconds): |
| 232 | + |
| 233 | + # We use a custom tick because we expect the following: |
| 234 | + # |
| 235 | + # * At least one time check when creating the request |
| 236 | + # * At least one time check when processing the request |
| 237 | + # |
| 238 | + # >= 1 ticks are acceptable. |
| 239 | + with freeze_time(auto_tick_seconds=time_difference_from_now): |
231 | 240 | with pytest.raises(RequestTimeTooSkewed): |
232 | 241 | vws_client.get_target_record(target_id='a') |
233 | 242 |
|
|
0 commit comments