summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2012-08-15 09:45:28 +0200
committerAymeric Augustin <aymeric.augustin@m4x.org>2012-08-15 09:45:28 +0200
commite0ec7507ac6c9e08ddbdf8a3ddedc430b22c7be9 (patch)
treef976a6882a2b68ee78247df5e854392b3eb621d1
parent478a69314e0f1a7fb4e9fd80f2cd3b9f210cc780 (diff)
[py3] Fixed jsi18n test.
Also refactored said test to avoid leaking state (ie. active translation) when an error occurs.
-rw-r--r--tests/regressiontests/views/tests/i18n.py30
1 files changed, 16 insertions, 14 deletions
diff --git a/tests/regressiontests/views/tests/i18n.py b/tests/regressiontests/views/tests/i18n.py
index cb580267d2..601df6d512 100644
--- a/tests/regressiontests/views/tests/i18n.py
+++ b/tests/regressiontests/views/tests/i18n.py
@@ -7,7 +7,8 @@ from os import path
from django.conf import settings
from django.core.urlresolvers import reverse
from django.test import TestCase
-from django.utils.translation import override, activate, get_language
+from django.utils import six
+from django.utils.translation import override, get_language
from django.utils.text import javascript_quote
from ..urls import locale_dir
@@ -29,20 +30,21 @@ class I18NTests(TestCase):
def test_jsi18n(self):
"""The javascript_catalog can be deployed with language settings"""
- saved_lang = get_language()
for lang_code in ['es', 'fr', 'ru']:
- activate(lang_code)
- catalog = gettext.translation('djangojs', locale_dir, [lang_code])
- trans_txt = catalog.ugettext('this is to be translated')
- response = self.client.get('/views/jsi18n/')
- # in response content must to be a line like that:
- # catalog['this is to be translated'] = 'same_that_trans_txt'
- # javascript_quote is used to be able to check unicode strings
- self.assertContains(response, javascript_quote(trans_txt), 1)
- if lang_code == 'fr':
- # Message with context (msgctxt)
- self.assertContains(response, "['month name\x04May'] = 'mai';", 1)
- activate(saved_lang)
+ with override(lang_code):
+ catalog = gettext.translation('djangojs', locale_dir, [lang_code])
+ if six.PY3:
+ trans_txt = catalog.gettext('this is to be translated')
+ else:
+ trans_txt = catalog.ugettext('this is to be translated')
+ response = self.client.get('/views/jsi18n/')
+ # in response content must to be a line like that:
+ # catalog['this is to be translated'] = 'same_that_trans_txt'
+ # javascript_quote is used to be able to check unicode strings
+ self.assertContains(response, javascript_quote(trans_txt), 1)
+ if lang_code == 'fr':
+ # Message with context (msgctxt)
+ self.assertContains(response, "['month name\x04May'] = 'mai';", 1)
class JsI18NTests(TestCase):