Skip to content

Commit

Permalink
Fixed failing test around DST change.
Browse files Browse the repository at this point in the history
The timezone arithmetic done in JS can be off by one hour around DST
change. We work around this issue by adding one extra hour to the test
error margin when we detect a DST change is near.

Refs #20663.
  • Loading branch information
loic committed Nov 2, 2013
1 parent 2bba0d2 commit 757945b
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions tests/admin_widgets/tests.py
Expand Up @@ -2,7 +2,12 @@
from __future__ import unicode_literals

from datetime import datetime, timedelta
from unittest import TestCase
from unittest import TestCase, skipIf

try:
import pytz
except ImportError:
pytz = None

from django import forms
from django.conf import settings
Expand Down Expand Up @@ -635,6 +640,7 @@ class DateTimePickerSeleniumIETests(DateTimePickerSeleniumFirefoxTests):
webdriver_class = 'selenium.webdriver.ie.webdriver.WebDriver'


@skipIf(pytz is None, "this test requires pytz")
@override_settings(TIME_ZONE='Asia/Singapore')
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
class DateTimePickerShortcutsSeleniumFirefoxTests(AdminSeleniumWebDriverTestCase):
Expand All @@ -654,9 +660,18 @@ def test_date_time_picker_shortcuts(self):
"""
self.admin_login(username='super', password='secret', login_url='/')

now = datetime.now()
error_margin = timedelta(seconds=10)

# If we are neighbouring a DST, we add an hour of error margin.
tz = pytz.timezone('America/Chicago')
utc_now = datetime.now(pytz.utc)
tz_yesterday = (utc_now - timedelta(days=1)).astimezone(tz).tzname()
tz_tomorrow = (utc_now + timedelta(days=1)).astimezone(tz).tzname()
if tz_yesterday != tz_tomorrow:
error_margin += timedelta(hours=1)

now = datetime.now()

self.selenium.get('%s%s' % (self.live_server_url,
'/admin_widgets/member/add/'))

Expand Down

0 comments on commit 757945b

Please sign in to comment.