Code

Ticket #19136: 19136-tests.diff

File 19136-tests.diff, 6.0 KB (added by claudep, 21 months ago)

Testing with LiveServerTestCase

Line 
1diff --git a/tests/regressiontests/i18n/other/locale/de/LC_MESSAGES/djangojs.mo b/tests/regressiontests/i18n/other/locale/de/LC_MESSAGES/djangojs.mo
2new file mode 100644
3index 0000000..34ba691
4Binary files /dev/null and b/tests/regressiontests/i18n/other/locale/de/LC_MESSAGES/djangojs.mo differ
5diff --git a/tests/regressiontests/i18n/other/locale/de/LC_MESSAGES/djangojs.po b/tests/regressiontests/i18n/other/locale/de/LC_MESSAGES/djangojs.po
6new file mode 100644
7index 0000000..88cc35e
8--- /dev/null
9+++ b/tests/regressiontests/i18n/other/locale/de/LC_MESSAGES/djangojs.po
10@@ -0,0 +1,40 @@
11+# SOME DESCRIPTIVE TITLE.
12+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
13+# This file is distributed under the same license as the PACKAGE package.
14+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
15+#
16+msgid ""
17+msgstr ""
18+"Project-Id-Version: django tests\n"
19+"Report-Msgid-Bugs-To: \n"
20+"POT-Creation-Date: 2010-02-14 17:33+0100\n"
21+"PO-Revision-Date: 2011-01-21 21:37-0300\n"
22+"Last-Translator: Jannis Leidel <jannis@leidel.info>\n"
23+"Language-Team: de <de@li.org>\n"
24+"MIME-Version: 1.0\n"
25+"Content-Type: text/plain; charset=UTF-8\n"
26+"Content-Transfer-Encoding: 8bit\n"
27+"Plural-Forms: nplurals=2; plural=(n != 1)\n"
28+
29+#: models.py:7
30+msgctxt "month name"
31+msgid "May"
32+msgstr "Mai"
33+
34+#: models.py:9
35+msgctxt "verb"
36+msgid "May"
37+msgstr "Kann"
38+
39+#: models.py:11
40+msgid "%s item"
41+msgid_plural "%s items"
42+msgstr[0] "%s Element"
43+msgstr[1] "%s Elemente"
44+
45+#: models.py:11
46+msgctxt "search"
47+msgid "%s result"
48+msgid_plural "%s results"
49+msgstr[0] "%s Resultat"
50+msgstr[1] "%s Resultate"
51diff --git a/tests/regressiontests/i18n/templates/javascript_i18n.html b/tests/regressiontests/i18n/templates/javascript_i18n.html
52new file mode 100644
53index 0000000..49b22f4
54--- /dev/null
55+++ b/tests/regressiontests/i18n/templates/javascript_i18n.html
56@@ -0,0 +1,44 @@
57+<html>
58+<head>
59+  <script type="text/javascript" src="/jsi18n/"></script>
60+</head>
61+
62+<body>
63+  <p id="gettext">
64+    <script type="text/javascript">
65+    document.write(gettext("Choose"));
66+    </script>
67+  </p>
68+
69+  <p id="ngettext_sing">
70+    <script type="text/javascript">
71+    document.write(interpolate(ngettext("%s item", "%s items", 1), [1]));
72+    </script>
73+  </p>
74+
75+  <p id="ngettext_plur">
76+    <script type="text/javascript">
77+    document.write(interpolate(ngettext("%s item", "%s items", 455), [455]));
78+    </script>
79+  </p>
80+
81+  <p id="pgettext">
82+    <script type="text/javascript">
83+    document.write(pgettext("verb", "May"));
84+    </script>
85+  </p>
86+
87+  <p id="npgettext_sing">
88+    <script type="text/javascript">
89+    document.write(interpolate(npgettext("search", "%s result", "%s results", 1), [1]));
90+    </script>
91+  </p>
92+
93+  <p id="npgettext_plur">
94+    <script type="text/javascript">
95+    document.write(interpolate(npgettext("search", "%s result", "%s results", 455), [455]));
96+    </script>
97+  </p>
98+
99+</body>
100+</html>
101diff --git a/tests/regressiontests/i18n/tests.py b/tests/regressiontests/i18n/tests.py
102index bce3d61..bf121f3 100644
103--- a/tests/regressiontests/i18n/tests.py
104+++ b/tests/regressiontests/i18n/tests.py
105@@ -10,7 +10,7 @@ from threading import local
106 from django.conf import settings
107 from django.template import Template, Context
108 from django.template.base import TemplateSyntaxError
109-from django.test import TestCase, RequestFactory
110+from django.test import LiveServerTestCase, TestCase, RequestFactory
111 from django.test.utils import override_settings
112 from django.utils import translation
113 from django.utils.formats import (get_format, date_format, time_format,
114@@ -43,6 +43,8 @@ from .patterns.tests import (URLRedirectWithoutTrailingSlashTests,
115     URLRedirectWithoutTrailingSlashSettingTests, URLNamespaceTests,
116     URLPrefixTests, URLResponseTests, URLRedirectTests, PathUnusedTests)
117 
118+from selenium.webdriver.firefox.webdriver import WebDriver
119+
120 
121 here = os.path.dirname(os.path.abspath(__file__))
122 
123@@ -1036,3 +1038,36 @@ class MultipleLocaleActivationTests(TestCase):
124             t = Template("{% load i18n %}{% blocktrans %}No{% endblocktrans %}")
125         with translation.override('nl'):
126             self.assertEqual(t.render(Context({})), 'Nee')
127+
128+
129+class JavascriptI18nTests(LiveServerTestCase):
130+    urls = 'regressiontests.i18n.urls'
131+
132+    @classmethod
133+    def setUpClass(cls):
134+        cls.selenium = WebDriver()
135+        super(JavascriptI18nTests, cls).setUpClass()
136+
137+    @classmethod
138+    def tearDownClass(cls):
139+        cls.selenium.quit()
140+        super(JavascriptI18nTests, cls).tearDownClass()
141+
142+    @override_settings(LANGUAGE_CODE='de')
143+    def test_javascript_gettext(self):
144+        extended_apps = list(settings.INSTALLED_APPS) + ['regressiontests.i18n.other']
145+        with self.settings(INSTALLED_APPS=extended_apps):
146+            self.selenium.get('%s%s' % (self.live_server_url, '/javascript_i18n/'))
147+
148+            elem = self.selenium.find_element_by_id("gettext")
149+            self.assertEqual(elem.text, "Auswählen")
150+            elem = self.selenium.find_element_by_id("ngettext_sing")
151+            self.assertEqual(elem.text, "1 Element")
152+            elem = self.selenium.find_element_by_id("ngettext_plur")
153+            self.assertEqual(elem.text, "455 Elemente")
154+            elem = self.selenium.find_element_by_id("pgettext")
155+            self.assertEqual(elem.text, "Kann")
156+            elem = self.selenium.find_element_by_id("npgettext_sing")
157+            self.assertEqual(elem.text, "1 Resultat")
158+            elem = self.selenium.find_element_by_id("npgettext_plur")
159+            self.assertEqual(elem.text, "455 Resultate")
160diff --git a/tests/regressiontests/i18n/urls.py b/tests/regressiontests/i18n/urls.py
161new file mode 100644
162index 0000000..ec5e361
163--- /dev/null
164+++ b/tests/regressiontests/i18n/urls.py
165@@ -0,0 +1,10 @@
166+from django.conf.urls import patterns
167+from django.views.generic import TemplateView
168+
169+
170+urlpatterns = patterns('',
171+    (r'^javascript_i18n/$', TemplateView.as_view(template_name='javascript_i18n.html')),
172+    (r'^jsi18n/$', 'django.views.i18n.javascript_catalog',
173+        {'packages': ('django.contrib.admin','regressiontests.i18n.other'),}
174+    ),
175+)