|
|
@ -34,6 +34,27 @@ def has_encoding(name): |
|
|
|
return False |
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FixedOffset(datetime.tzinfo): |
|
|
|
|
|
|
|
"""Fixed offset in hours east from UTC. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
This is a slight adaptation of the ``FixedOffset`` example found in |
|
|
|
|
|
|
|
https://docs.python.org/2.7/library/datetime.html. |
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, hours, name): |
|
|
|
|
|
|
|
self.__offset = datetime.timedelta(hours=hours) |
|
|
|
|
|
|
|
self.__name = name |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def utcoffset(self, dt): |
|
|
|
|
|
|
|
return self.__offset |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def tzname(self, dt): |
|
|
|
|
|
|
|
return self.__name |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def dst(self, dt): |
|
|
|
|
|
|
|
return datetime.timedelta() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestJSON(object): |
|
|
|
class TestJSON(object): |
|
|
|
def test_ignore_cached_json(self, app): |
|
|
|
def test_ignore_cached_json(self, app): |
|
|
|
with app.test_request_context('/', method='POST', data='malformed', |
|
|
|
with app.test_request_context('/', method='POST', data='malformed', |
|
|
@ -180,9 +201,9 @@ class TestJSON(object): |
|
|
|
@pytest.mark.parametrize('tz', (('UTC', 0), ('PST', -8), ('KST', 9))) |
|
|
|
@pytest.mark.parametrize('tz', (('UTC', 0), ('PST', -8), ('KST', 9))) |
|
|
|
def test_jsonify_aware_datetimes(self, tz): |
|
|
|
def test_jsonify_aware_datetimes(self, tz): |
|
|
|
"""Test if aware datetime.datetime objects are converted into GMT.""" |
|
|
|
"""Test if aware datetime.datetime objects are converted into GMT.""" |
|
|
|
tzinfo = datetime.timezone(datetime.timedelta(hours=tz[1]), name=tz[0]) |
|
|
|
tzinfo = FixedOffset(hours=tz[1], name=tz[0]) |
|
|
|
dt = datetime.datetime(2017, 1, 1, 12, 34, 56, tzinfo=tzinfo) |
|
|
|
dt = datetime.datetime(2017, 1, 1, 12, 34, 56, tzinfo=tzinfo) |
|
|
|
gmt = datetime.timezone(datetime.timedelta(), name='GMT') |
|
|
|
gmt = FixedOffset(hours=0, name='GMT') |
|
|
|
expected = dt.astimezone(gmt).strftime('"%a, %d %b %Y %H:%M:%S %Z"') |
|
|
|
expected = dt.astimezone(gmt).strftime('"%a, %d %b %Y %H:%M:%S %Z"') |
|
|
|
assert flask.json.JSONEncoder().encode(dt) == expected |
|
|
|
assert flask.json.JSONEncoder().encode(dt) == expected |
|
|
|
|
|
|
|
|
|
|
|