summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJulien Phalip <jphalip@gmail.com>2011-10-20 12:14:06 +0000
committerJulien Phalip <jphalip@gmail.com>2011-10-20 12:14:06 +0000
commit1452cecd154c9a77af85e6a5b09e334797779be4 (patch)
treede4606384459c8daf851c92241793a133127e416 /tests
parent51b8f0a2402d56ec84c2f12045291c0f7e6862e6 (diff)
Fixed 16938 -- Ensured that the active locale's formats take precedence over the default settings even if they would be interpreted as False in a conditional test (e.g. 0 or empty string). Thanks to pikerr for the report and initial patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17017 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/i18n/tests.py36
1 files changed, 35 insertions, 1 deletions
diff --git a/tests/regressiontests/i18n/tests.py b/tests/regressiontests/i18n/tests.py
index bfed0ec882..17395ffb24 100644
--- a/tests/regressiontests/i18n/tests.py
+++ b/tests/regressiontests/i18n/tests.py
@@ -14,7 +14,8 @@ from django.test import TestCase, RequestFactory
from django.test.utils import override_settings
from django.utils import translation
from django.utils.formats import (get_format, date_format, time_format,
- localize, localize_input, iter_format_modules, get_format_modules)
+ localize, localize_input, iter_format_modules, get_format_modules,
+ number_format)
from django.utils.importlib import import_module
from django.utils.numberformat import format as nformat
from django.utils.safestring import mark_safe, SafeString, SafeUnicode
@@ -397,6 +398,39 @@ class FormattingTests(TestCase):
self.assertEqual(u'66666.67', Template('{{ n|floatformat:2 }}').render(self.ctxt))
self.assertEqual(u'100000.0', Template('{{ f|floatformat }}').render(self.ctxt))
+ def test_false_like_locale_formats(self):
+ """
+ Ensure that the active locale's formats take precedence over the
+ default settings even if they would be interpreted as False in a
+ conditional test (e.g. 0 or empty string).
+ Refs #16938.
+ """
+ from django.conf.locale.fr import formats as fr_formats
+
+ # Back up original formats
+ backup_THOUSAND_SEPARATOR = fr_formats.THOUSAND_SEPARATOR
+ backup_FIRST_DAY_OF_WEEK = fr_formats.FIRST_DAY_OF_WEEK
+
+ # Set formats that would get interpreted as False in a conditional test
+ fr_formats.THOUSAND_SEPARATOR = ''
+ fr_formats.FIRST_DAY_OF_WEEK = 0
+
+ with translation.override('fr'):
+ with self.settings(USE_L10N=True, USE_THOUSAND_SEPARATOR=True,
+ THOUSAND_SEPARATOR='!'):
+ self.assertEqual('', get_format('THOUSAND_SEPARATOR'))
+ # Even a second time (after the format has been cached)...
+ self.assertEqual('', get_format('THOUSAND_SEPARATOR'))
+
+ with self.settings(USE_L10N=True, FIRST_DAY_OF_WEEK=1):
+ self.assertEqual(0, get_format('FIRST_DAY_OF_WEEK'))
+ # Even a second time (after the format has been cached)...
+ self.assertEqual(0, get_format('FIRST_DAY_OF_WEEK'))
+
+ # Restore original formats
+ fr_formats.THOUSAND_SEPARATOR = backup_THOUSAND_SEPARATOR
+ fr_formats.FIRST_DAY_OF_WEEK = backup_FIRST_DAY_OF_WEEK
+
def test_l10n_enabled(self):
settings.USE_L10N = True
# Catalan locale