mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Fixed #20663 -- "Today" and "now" admin shortcuts.
Changed the shortcuts next to date and time intput widgets to account for the current timezone. Refs #7717, #14253 and #18768.
This commit is contained in:
committed by
Aymeric Augustin
parent
404870ee1f
commit
7e6d852bac
@@ -1,7 +1,7 @@
|
||||
# encoding: utf-8
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timedelta
|
||||
from unittest import TestCase
|
||||
|
||||
from django import forms
|
||||
@@ -526,6 +526,64 @@ class DateTimePickerSeleniumIETests(DateTimePickerSeleniumFirefoxTests):
|
||||
webdriver_class = 'selenium.webdriver.ie.webdriver.WebDriver'
|
||||
|
||||
|
||||
@override_settings(TIME_ZONE='Asia/Singapore')
|
||||
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
|
||||
class DateTimePickerShortcutsSeleniumFirefoxTests(AdminSeleniumWebDriverTestCase):
|
||||
available_apps = ['admin_widgets'] + AdminSeleniumWebDriverTestCase.available_apps
|
||||
fixtures = ['admin-widgets-users.xml']
|
||||
urls = "admin_widgets.urls"
|
||||
webdriver_class = 'selenium.webdriver.firefox.webdriver.WebDriver'
|
||||
|
||||
def test_date_time_picker_shortcuts(self):
|
||||
"""
|
||||
Ensure that date/time/datetime picker shortcuts work in the current time zone.
|
||||
Refs #20663.
|
||||
|
||||
This test case is fairly tricky, it relies on selenium still running the browser
|
||||
in the default time zone "America/Chicago" despite `override_settings` changing
|
||||
the time zone to "Asia/Singapore".
|
||||
"""
|
||||
self.admin_login(username='super', password='secret', login_url='/')
|
||||
|
||||
now = datetime.now()
|
||||
error_margin = timedelta(seconds=10)
|
||||
|
||||
self.selenium.get('%s%s' % (self.live_server_url,
|
||||
'/admin_widgets/member/add/'))
|
||||
|
||||
self.selenium.find_element_by_id('id_name').send_keys('test')
|
||||
|
||||
# Click on the "today" and "now" shortcuts.
|
||||
shortcuts = self.selenium.find_elements_by_css_selector(
|
||||
'.field-birthdate .datetimeshortcuts')
|
||||
|
||||
for shortcut in shortcuts:
|
||||
shortcut.find_element_by_tag_name('a').click()
|
||||
|
||||
# Check that there is a time zone mismatch warning.
|
||||
# Warning: This would effectively fail if the TIME_ZONE defined in the
|
||||
# settings has the same UTC offset as "Asia/Singapore" because the
|
||||
# mismatch warning would be rightfully missing from the page.
|
||||
self.selenium.find_elements_by_css_selector(
|
||||
'.field-birthdate .timezonewarning')
|
||||
|
||||
# Submit the form.
|
||||
self.selenium.find_element_by_tag_name('form').submit()
|
||||
self.wait_page_loaded()
|
||||
|
||||
# Make sure that "now" in javascript is within 10 seconds
|
||||
# from "now" on the server side.
|
||||
member = models.Member.objects.get(name='test')
|
||||
self.assertGreater(member.birthdate, now - error_margin)
|
||||
self.assertLess(member.birthdate, now + error_margin)
|
||||
|
||||
class DateTimePickerShortcutsSeleniumChromeTests(DateTimePickerShortcutsSeleniumFirefoxTests):
|
||||
webdriver_class = 'selenium.webdriver.chrome.webdriver.WebDriver'
|
||||
|
||||
class DateTimePickerShortcutsSeleniumIETests(DateTimePickerShortcutsSeleniumFirefoxTests):
|
||||
webdriver_class = 'selenium.webdriver.ie.webdriver.WebDriver'
|
||||
|
||||
|
||||
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
|
||||
class HorizontalVerticalFilterSeleniumFirefoxTests(AdminSeleniumWebDriverTestCase):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user