|
11 | 11 | CacheDownloader,
|
12 | 12 | FailedDownloadError,
|
13 | 13 | _cache_hit,
|
| 14 | + _lastmod_from_response, |
14 | 15 | url_to_cache_filename,
|
15 | 16 | )
|
16 | 17 |
|
17 | 18 | DEFAULT_RESPONSE_URL = "https://example.com/schema1.json"
|
| 19 | +DEFAULT_LASTMOD = "Sun, 01 Jan 2000 00:00:01 GMT" |
18 | 20 |
|
19 | 21 |
|
20 | 22 | def add_default_response():
|
21 | 23 | responses.add(
|
22 | 24 | "GET",
|
23 | 25 | DEFAULT_RESPONSE_URL,
|
24 |
| - headers={"Last-Modified": "Sun, 01 Jan 2000 00:00:01 GMT"}, |
| 26 | + headers={"Last-Modified": DEFAULT_LASTMOD}, |
25 | 27 | json={},
|
26 | 28 | match_querystring=None,
|
27 | 29 | )
|
@@ -341,3 +343,37 @@ def dummy_validate_bytes(data):
|
341 | 343 | assert fp.read() == b"{}"
|
342 | 344 | # assert that the validator was not run
|
343 | 345 | assert validator_ran is False
|
| 346 | + |
| 347 | + |
| 348 | +def test_lastmod_from_header_uses_gmtime(request, monkeypatch, default_response): |
| 349 | + """ |
| 350 | + Regression test for https://github.com/python-jsonschema/check-jsonschema/pull/565 |
| 351 | +
|
| 352 | + The time was converted in local time, when UTC/GMT was desired. |
| 353 | + """ |
| 354 | + |
| 355 | + def final_tzset(): |
| 356 | + time.tzset() |
| 357 | + |
| 358 | + request.addfinalizer(final_tzset) |
| 359 | + |
| 360 | + response = requests.get(DEFAULT_RESPONSE_URL, stream=True) |
| 361 | + |
| 362 | + with monkeypatch.context() as m: |
| 363 | + m.setenv("TZ", "GMT0") |
| 364 | + time.tzset() |
| 365 | + gmt_parsed_time = _lastmod_from_response(response) |
| 366 | + |
| 367 | + with monkeypatch.context() as m: |
| 368 | + m.setenv("TZ", "EST5") |
| 369 | + time.tzset() |
| 370 | + est_parsed_time = _lastmod_from_response(response) |
| 371 | + |
| 372 | + with monkeypatch.context() as m: |
| 373 | + m.setenv("TZ", "UTC0") |
| 374 | + time.tzset() |
| 375 | + utc_parsed_time = _lastmod_from_response(response) |
| 376 | + |
| 377 | + # assert that they all match |
| 378 | + assert gmt_parsed_time == utc_parsed_time |
| 379 | + assert gmt_parsed_time == est_parsed_time |
0 commit comments