forked from orbit-oss/flask
Add UTs for #2372
test_encode_aware_datetime() fails for non-UTC timezones due to the bug.
This commit is contained in:
parent
2c97ed985e
commit
d75d83defd
2 changed files with 11 additions and 0 deletions
|
|
@ -23,6 +23,7 @@ from werkzeug.http import parse_cache_control_header, parse_options_header
|
||||||
from werkzeug.http import http_date
|
from werkzeug.http import http_date
|
||||||
from flask._compat import StringIO, text_type
|
from flask._compat import StringIO, text_type
|
||||||
from flask.helpers import get_debug_flag, make_response
|
from flask.helpers import get_debug_flag, make_response
|
||||||
|
from pytz import timezone
|
||||||
|
|
||||||
|
|
||||||
def has_encoding(name):
|
def has_encoding(name):
|
||||||
|
|
@ -177,6 +178,15 @@ class TestJSON(object):
|
||||||
assert rv.mimetype == 'application/json'
|
assert rv.mimetype == 'application/json'
|
||||||
assert flask.json.loads(rv.data)['x'] == http_date(d.timetuple())
|
assert flask.json.loads(rv.data)['x'] == http_date(d.timetuple())
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('tzname', ('UTC', 'PST8PDT', 'Asia/Seoul'))
|
||||||
|
def test_jsonify_aware_datetimes(self, tzname):
|
||||||
|
"""Test if aware datetime.datetime objects are converted into GMT."""
|
||||||
|
dt_naive = datetime.datetime(2017, 1, 1, 12, 34, 56)
|
||||||
|
dt_aware = timezone(tzname).localize(dt_naive)
|
||||||
|
dt_as_gmt = dt_aware.astimezone(timezone('GMT'))
|
||||||
|
expected = dt_as_gmt.strftime('"%a, %d %b %Y %H:%M:%S %Z"')
|
||||||
|
assert flask.json.JSONEncoder().encode(dt_aware) == expected
|
||||||
|
|
||||||
def test_jsonify_uuid_types(self, app, client):
|
def test_jsonify_uuid_types(self, app, client):
|
||||||
"""Test jsonify with uuid.UUID types"""
|
"""Test jsonify with uuid.UUID types"""
|
||||||
|
|
||||||
|
|
|
||||||
1
tox.ini
1
tox.ini
|
|
@ -15,6 +15,7 @@ deps =
|
||||||
coverage
|
coverage
|
||||||
greenlet
|
greenlet
|
||||||
blinker
|
blinker
|
||||||
|
pytz
|
||||||
|
|
||||||
lowest: Werkzeug==0.9
|
lowest: Werkzeug==0.9
|
||||||
lowest: Jinja2==2.4
|
lowest: Jinja2==2.4
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue