From 6bb2175ed65456dda2f8ba584f206ba4bbd43dbc Mon Sep 17 00:00:00 2001 From: Moritz Sichert Date: Sun, 23 Feb 2014 15:10:31 +0100 Subject: Fixed #22106 -- Allowed using more than one instance of javascript_catalog per project. --- tests/view_tests/templates/jsi18n-multi-catalogs.html | 17 +++++++++++++++++ tests/view_tests/tests/test_i18n.py | 14 +++++++++++++- tests/view_tests/urls.py | 13 +++++++++++++ tests/view_tests/views.py | 4 ++++ 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 tests/view_tests/templates/jsi18n-multi-catalogs.html (limited to 'tests') diff --git a/tests/view_tests/templates/jsi18n-multi-catalogs.html b/tests/view_tests/templates/jsi18n-multi-catalogs.html new file mode 100644 index 0000000000..8ec902e1c7 --- /dev/null +++ b/tests/view_tests/templates/jsi18n-multi-catalogs.html @@ -0,0 +1,17 @@ + + + + + +

+ +

+

+ +

+ + diff --git a/tests/view_tests/tests/test_i18n.py b/tests/view_tests/tests/test_i18n.py index ae3025b5f1..04643d0508 100644 --- a/tests/view_tests/tests/test_i18n.py +++ b/tests/view_tests/tests/test_i18n.py @@ -1,4 +1,6 @@ # -*- coding:utf-8 -*- +from __future__ import unicode_literals + import gettext import json import os @@ -100,7 +102,7 @@ class I18NTests(TestCase): self.assertContains(response, json.dumps(trans_txt), 1) if lang_code == 'fr': # Message with context (msgctxt) - self.assertContains(response, r'"month name\u0004May": "mai"', 1) + self.assertContains(response, '"month name\\u0004May": "mai"', 1) @override_settings(ROOT_URLCONF='view_tests.urls') @@ -270,6 +272,16 @@ class JavascriptI18nTests(LiveServerTestCase): elem = self.selenium.find_element_by_id("npgettext_plur") self.assertEqual(elem.text, "455 Resultate") + @modify_settings(INSTALLED_APPS={'append': ['view_tests.app1', 'view_tests.app2']}) + @override_settings(LANGUAGE_CODE='fr') + def test_multiple_catalogs(self): + self.selenium.get('%s%s' % (self.live_server_url, '/jsi18n_multi_catalogs/')) + + elem = self.selenium.find_element_by_id('app1string') + self.assertEqual(elem.text, 'il faut traduire cette chaîne de caractères de app1') + elem = self.selenium.find_element_by_id('app2string') + self.assertEqual(elem.text, 'il faut traduire cette chaîne de caractères de app2') + class JavascriptI18nChromeTests(JavascriptI18nTests): webdriver_class = 'selenium.webdriver.chrome.webdriver.WebDriver' diff --git a/tests/view_tests/urls.py b/tests/view_tests/urls.py index 061dd19751..1d34b1f934 100644 --- a/tests/view_tests/urls.py +++ b/tests/view_tests/urls.py @@ -38,6 +38,16 @@ js_info_dict_admin = { 'packages': ('django.contrib.admin', 'view_tests'), } +js_info_dict_app1 = { + 'domain': 'djangojs', + 'packages': ('view_tests.app1',), +} + +js_info_dict_app2 = { + 'domain': 'djangojs', + 'packages': ('view_tests.app2',), +} + js_info_dict_app5 = { 'domain': 'djangojs', 'packages': ('view_tests.app5',), @@ -64,12 +74,15 @@ urlpatterns = [ # i18n views url(r'^i18n/', include('django.conf.urls.i18n')), url(r'^jsi18n/$', i18n.javascript_catalog, js_info_dict), + url(r'^jsi18n/app1/$', i18n.javascript_catalog, js_info_dict_app1), + url(r'^jsi18n/app2/$', i18n.javascript_catalog, js_info_dict_app2), url(r'^jsi18n/app5/$', i18n.javascript_catalog, js_info_dict_app5), url(r'^jsi18n_english_translation/$', i18n.javascript_catalog, js_info_dict_english_translation), url(r'^jsi18n_multi_packages1/$', i18n.javascript_catalog, js_info_dict_multi_packages1), url(r'^jsi18n_multi_packages2/$', i18n.javascript_catalog, js_info_dict_multi_packages2), url(r'^jsi18n_admin/$', i18n.javascript_catalog, js_info_dict_admin), url(r'^jsi18n_template/$', views.jsi18n), + url(r'^jsi18n_multi_catalogs/$', views.jsi18n_multi_catalogs), # Static views url(r'^site_media/(?P.*)$', static.serve, {'document_root': media_dir}), diff --git a/tests/view_tests/views.py b/tests/view_tests/views.py index ad688573df..debc7bd7df 100644 --- a/tests/view_tests/views.py +++ b/tests/view_tests/views.py @@ -82,6 +82,10 @@ def jsi18n(request): return render_to_response('jsi18n.html') +def jsi18n_multi_catalogs(request): + return render_to_response('jsi18n-multi-catalogs.html') + + def raises_template_does_not_exist(request, path='i_dont_exist.html'): # We need to inspect the HTML generated by the fancy 500 debug view but # the test client ignores it, so we send it explicitly. -- cgit v1.3