summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/deprecation/tests.py23
-rw-r--r--tests/i18n/tests.py25
2 files changed, 46 insertions, 2 deletions
diff --git a/tests/deprecation/tests.py b/tests/deprecation/tests.py
index f949bea24e..7d9ed16636 100644
--- a/tests/deprecation/tests.py
+++ b/tests/deprecation/tests.py
@@ -1,8 +1,8 @@
from __future__ import unicode_literals
import warnings
-from django.test import SimpleTestCase, RequestFactory
-from django.utils import six
+from django.test import SimpleTestCase, RequestFactory, override_settings
+from django.utils import six, translation
from django.utils.deprecation import RenameMethodsBase
@@ -186,3 +186,22 @@ class DeprecatingRequestMergeDictTest(SimpleTestCase):
'`request.POST` instead.',
'`MergeDict` is deprecated, use `dict.update()` instead.',
])
+
+
+@override_settings(USE_I18N=True)
+class DeprecatedChineseLanguageCodes(SimpleTestCase):
+ def test_deprecation_warning(self):
+ warnings.simplefilter('always')
+
+ with warnings.catch_warnings(record=True) as recorded:
+ with translation.override('zh-cn'):
+ pass
+ with translation.override('zh-tw'):
+ pass
+ msgs = [str(warning.message) for warning in recorded]
+ self.assertEqual(msgs, [
+ "The use of the language code 'zh-cn' is deprecated. "
+ "Please use the 'zh-hans' translation instead.",
+ "The use of the language code 'zh-tw' is deprecated. "
+ "Please use the 'zh-hant' translation instead.",
+ ])
diff --git a/tests/i18n/tests.py b/tests/i18n/tests.py
index 76f59bf919..f68a7361f6 100644
--- a/tests/i18n/tests.py
+++ b/tests/i18n/tests.py
@@ -871,6 +871,31 @@ class MiscTests(TransRealMixin, TestCase):
r.META = {'HTTP_ACCEPT_LANGUAGE': 'zh-cn,de'}
self.assertEqual(g(r), 'zh-cn')
+ @override_settings(
+ LANGUAGES=(
+ ('en', 'English'),
+ ('zh-hans', 'Simplified Chinese'),
+ ('zh-hant', 'Traditional Chinese'),
+ )
+ )
+ def test_support_for_deprecated_chinese_language_codes(self):
+ """
+ Some browsers (Firefox, IE etc) use deprecated language codes. As these
+ language codes will be removed in Django 1.9, these will be incorrectly
+ matched. For example zh-tw (traditional) will be interpreted as zh-hans
+ (simplified), which is wrong. So we should also accept these deprecated
+ language codes.
+
+ refs #18419 -- this is explicitly for browser compatibility
+ """
+ g = get_language_from_request
+ r = self.rf.get('/')
+ r.COOKIES = {}
+ r.META = {'HTTP_ACCEPT_LANGUAGE': 'zh-cn,en'}
+ self.assertEqual(g(r), 'zh-hans')
+ r.META = {'HTTP_ACCEPT_LANGUAGE': 'zh-tw,en'}
+ self.assertEqual(g(r), 'zh-hant')
+
def test_parse_language_cookie(self):
"""
Now test that we parse language preferences stored in a cookie correctly.