summaryrefslogtreecommitdiff
path: root/tests/admin_widgets
diff options
context:
space:
mode:
authorMaxime Turcotte <maxime.turcotte@savoirfairelinux.com>2014-04-15 15:01:55 -0400
committerTim Graham <timograham@gmail.com>2014-08-13 20:36:26 -0400
commit25e06bca57c068d4b9e9b4221b16a667ccb0d38e (patch)
treed51bf0343202ed0130fd6fc08681f18a915f356c /tests/admin_widgets
parent2a9f44dfbe293a1217097acc34993f48c0139e99 (diff)
Fixed #18767 -- Fixed admin calendar for other locales than English.
Refactored openCalendar function from DateTimeShortcuts.js. Now, when entered manually in the input field, the date will show up correctly on the calendar for locales that don't use "-" for separator. Thanks charettes for revivew and Alexey Boriskin for some of the patch.
Diffstat (limited to 'tests/admin_widgets')
-rw-r--r--tests/admin_widgets/tests.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/admin_widgets/tests.py b/tests/admin_widgets/tests.py
index 83ae968523..fb31334b28 100644
--- a/tests/admin_widgets/tests.py
+++ b/tests/admin_widgets/tests.py
@@ -2,6 +2,9 @@
from __future__ import unicode_literals
from datetime import datetime, timedelta
+import gettext
+from importlib import import_module
+import os
from unittest import TestCase, skipIf
try:
@@ -637,6 +640,50 @@ class DateTimePickerSeleniumFirefoxTests(AdminSeleniumWebDriverTestCase):
self.assertEqual(len(selected), 0)
+ def test_calendar_show_date_from_input(self):
+ """
+ Ensure that the calendar show the date from the input field for every
+ locale supported by django.
+ """
+ self.admin_login(username='super', password='secret', login_url='/')
+
+ # Enter test data
+ member = models.Member.objects.create(name='Bob', birthdate=datetime(1984, 05, 15), gender='M')
+
+ # Get month names translations for every locales
+ month_string = 'January February March April May June July August September October November December'
+ path = os.path.join(os.path.dirname(import_module('django.contrib.admin').__file__), 'locale')
+ for language_code, language_name in settings.LANGUAGES:
+ try:
+ catalog = gettext.translation('djangojs', path, [language_code])
+ except IOError:
+ continue
+ if month_string in catalog._catalog:
+ month_names = catalog._catalog[month_string]
+ else:
+ month_names = month_string
+
+ # Get the expected caption
+ may_translation = month_names.split(' ')[4]
+ expected_caption = '{0:s} {1:d}'.format(may_translation, 1984)
+
+ # Test with every locale
+ with override_settings(LANGUAGE_CODE=language_code, USE_L10N=True):
+
+ # Open a page that has a date picker widget
+ self.selenium.get('{}{}'.format(self.live_server_url,
+ '/admin_widgets/member/{}/'.format(member.pk)))
+
+ # Click on the calendar icon
+ self.selenium.find_element_by_id('calendarlink0').click()
+
+ # Get the calendar caption
+ calendar0 = self.selenium.find_element_by_id('calendarin0')
+ caption = calendar0.find_element_by_tag_name('caption')
+
+ # Make sure that the right month and year are displayed
+ self.assertEqual(caption.text, expected_caption)
+
class DateTimePickerSeleniumChromeTests(DateTimePickerSeleniumFirefoxTests):
webdriver_class = 'selenium.webdriver.chrome.webdriver.WebDriver'