Skip to content

Commit 03d7580

Browse files
committed
Add a regression test for localtime handling
1 parent 578465e commit 03d7580

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

tests/unit/test_cachedownloader.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,19 @@
1111
CacheDownloader,
1212
FailedDownloadError,
1313
_cache_hit,
14+
_lastmod_from_response,
1415
url_to_cache_filename,
1516
)
1617

1718
DEFAULT_RESPONSE_URL = "https://example.com/schema1.json"
19+
DEFAULT_LASTMOD = "Sun, 01 Jan 2000 00:00:01 GMT"
1820

1921

2022
def add_default_response():
2123
responses.add(
2224
"GET",
2325
DEFAULT_RESPONSE_URL,
24-
headers={"Last-Modified": "Sun, 01 Jan 2000 00:00:01 GMT"},
26+
headers={"Last-Modified": DEFAULT_LASTMOD},
2527
json={},
2628
match_querystring=None,
2729
)
@@ -341,3 +343,37 @@ def dummy_validate_bytes(data):
341343
assert fp.read() == b"{}"
342344
# assert that the validator was not run
343345
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

Comments
 (0)