[py3] Fixed jsi18n test.

Also refactored said test to avoid leaking state (ie. active
translation) when an error occurs.
This commit is contained in:
Aymeric Augustin 2012-08-15 09:45:28 +02:00
parent 478a69314e
commit e0ec7507ac
1 changed files with 16 additions and 14 deletions

View File

@ -7,7 +7,8 @@ from os import path
from django.conf import settings from django.conf import settings
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.test import TestCase 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 django.utils.text import javascript_quote
from ..urls import locale_dir from ..urls import locale_dir
@ -29,10 +30,12 @@ class I18NTests(TestCase):
def test_jsi18n(self): def test_jsi18n(self):
"""The javascript_catalog can be deployed with language settings""" """The javascript_catalog can be deployed with language settings"""
saved_lang = get_language()
for lang_code in ['es', 'fr', 'ru']: for lang_code in ['es', 'fr', 'ru']:
activate(lang_code) with override(lang_code):
catalog = gettext.translation('djangojs', locale_dir, [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') trans_txt = catalog.ugettext('this is to be translated')
response = self.client.get('/views/jsi18n/') response = self.client.get('/views/jsi18n/')
# in response content must to be a line like that: # in response content must to be a line like that:
@ -42,7 +45,6 @@ class I18NTests(TestCase):
if lang_code == 'fr': if lang_code == 'fr':
# Message with context (msgctxt) # Message with context (msgctxt)
self.assertContains(response, "['month name\x04May'] = 'mai';", 1) self.assertContains(response, "['month name\x04May'] = 'mai';", 1)
activate(saved_lang)
class JsI18NTests(TestCase): class JsI18NTests(TestCase):