Ticket #19136: 19136-tests.diff

File 19136-tests.diff, 6.0 KB (added by Claude Paroz, 12 years ago)

Testing with LiveServerTestCase

  • new file tests/regressiontests/i18n/other/locale/de/LC_MESSAGES/djangojs.po

    diff --git a/tests/regressiontests/i18n/other/locale/de/LC_MESSAGES/djangojs.mo b/tests/regressiontests/i18n/other/locale/de/LC_MESSAGES/djangojs.mo
    new file mode 100644
    index 0000000..34ba691
    Binary files /dev/null and b/tests/regressiontests/i18n/other/locale/de/LC_MESSAGES/djangojs.mo differ
    diff --git a/tests/regressiontests/i18n/other/locale/de/LC_MESSAGES/djangojs.po b/tests/regressiontests/i18n/other/locale/de/LC_MESSAGES/djangojs.po
    new file mode 100644
    index 0000000..88cc35e
    - +  
     1# SOME DESCRIPTIVE TITLE.
     2# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
     3# This file is distributed under the same license as the PACKAGE package.
     4# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
     5#
     6msgid ""
     7msgstr ""
     8"Project-Id-Version: django tests\n"
     9"Report-Msgid-Bugs-To: \n"
     10"POT-Creation-Date: 2010-02-14 17:33+0100\n"
     11"PO-Revision-Date: 2011-01-21 21:37-0300\n"
     12"Last-Translator: Jannis Leidel <jannis@leidel.info>\n"
     13"Language-Team: de <de@li.org>\n"
     14"MIME-Version: 1.0\n"
     15"Content-Type: text/plain; charset=UTF-8\n"
     16"Content-Transfer-Encoding: 8bit\n"
     17"Plural-Forms: nplurals=2; plural=(n != 1)\n"
     18
     19#: models.py:7
     20msgctxt "month name"
     21msgid "May"
     22msgstr "Mai"
     23
     24#: models.py:9
     25msgctxt "verb"
     26msgid "May"
     27msgstr "Kann"
     28
     29#: models.py:11
     30msgid "%s item"
     31msgid_plural "%s items"
     32msgstr[0] "%s Element"
     33msgstr[1] "%s Elemente"
     34
     35#: models.py:11
     36msgctxt "search"
     37msgid "%s result"
     38msgid_plural "%s results"
     39msgstr[0] "%s Resultat"
     40msgstr[1] "%s Resultate"
  • new file tests/regressiontests/i18n/templates/javascript_i18n.html

    diff --git a/tests/regressiontests/i18n/templates/javascript_i18n.html b/tests/regressiontests/i18n/templates/javascript_i18n.html
    new file mode 100644
    index 0000000..49b22f4
    - +  
     1<html>
     2<head>
     3  <script type="text/javascript" src="/jsi18n/"></script>
     4</head>
     5
     6<body>
     7  <p id="gettext">
     8    <script type="text/javascript">
     9    document.write(gettext("Choose"));
     10    </script>
     11  </p>
     12
     13  <p id="ngettext_sing">
     14    <script type="text/javascript">
     15    document.write(interpolate(ngettext("%s item", "%s items", 1), [1]));
     16    </script>
     17  </p>
     18
     19  <p id="ngettext_plur">
     20    <script type="text/javascript">
     21    document.write(interpolate(ngettext("%s item", "%s items", 455), [455]));
     22    </script>
     23  </p>
     24
     25  <p id="pgettext">
     26    <script type="text/javascript">
     27    document.write(pgettext("verb", "May"));
     28    </script>
     29  </p>
     30
     31  <p id="npgettext_sing">
     32    <script type="text/javascript">
     33    document.write(interpolate(npgettext("search", "%s result", "%s results", 1), [1]));
     34    </script>
     35  </p>
     36
     37  <p id="npgettext_plur">
     38    <script type="text/javascript">
     39    document.write(interpolate(npgettext("search", "%s result", "%s results", 455), [455]));
     40    </script>
     41  </p>
     42
     43</body>
     44</html>
  • tests/regressiontests/i18n/tests.py

    diff --git a/tests/regressiontests/i18n/tests.py b/tests/regressiontests/i18n/tests.py
    index bce3d61..bf121f3 100644
    a b from threading import local  
    1010from django.conf import settings
    1111from django.template import Template, Context
    1212from django.template.base import TemplateSyntaxError
    13 from django.test import TestCase, RequestFactory
     13from django.test import LiveServerTestCase, TestCase, RequestFactory
    1414from django.test.utils import override_settings
    1515from django.utils import translation
    1616from django.utils.formats import (get_format, date_format, time_format,
    from .patterns.tests import (URLRedirectWithoutTrailingSlashTests,  
    4343    URLRedirectWithoutTrailingSlashSettingTests, URLNamespaceTests,
    4444    URLPrefixTests, URLResponseTests, URLRedirectTests, PathUnusedTests)
    4545
     46from selenium.webdriver.firefox.webdriver import WebDriver
     47
    4648
    4749here = os.path.dirname(os.path.abspath(__file__))
    4850
    class MultipleLocaleActivationTests(TestCase):  
    10361038            t = Template("{% load i18n %}{% blocktrans %}No{% endblocktrans %}")
    10371039        with translation.override('nl'):
    10381040            self.assertEqual(t.render(Context({})), 'Nee')
     1041
     1042
     1043class JavascriptI18nTests(LiveServerTestCase):
     1044    urls = 'regressiontests.i18n.urls'
     1045
     1046    @classmethod
     1047    def setUpClass(cls):
     1048        cls.selenium = WebDriver()
     1049        super(JavascriptI18nTests, cls).setUpClass()
     1050
     1051    @classmethod
     1052    def tearDownClass(cls):
     1053        cls.selenium.quit()
     1054        super(JavascriptI18nTests, cls).tearDownClass()
     1055
     1056    @override_settings(LANGUAGE_CODE='de')
     1057    def test_javascript_gettext(self):
     1058        extended_apps = list(settings.INSTALLED_APPS) + ['regressiontests.i18n.other']
     1059        with self.settings(INSTALLED_APPS=extended_apps):
     1060            self.selenium.get('%s%s' % (self.live_server_url, '/javascript_i18n/'))
     1061
     1062            elem = self.selenium.find_element_by_id("gettext")
     1063            self.assertEqual(elem.text, "Auswählen")
     1064            elem = self.selenium.find_element_by_id("ngettext_sing")
     1065            self.assertEqual(elem.text, "1 Element")
     1066            elem = self.selenium.find_element_by_id("ngettext_plur")
     1067            self.assertEqual(elem.text, "455 Elemente")
     1068            elem = self.selenium.find_element_by_id("pgettext")
     1069            self.assertEqual(elem.text, "Kann")
     1070            elem = self.selenium.find_element_by_id("npgettext_sing")
     1071            self.assertEqual(elem.text, "1 Resultat")
     1072            elem = self.selenium.find_element_by_id("npgettext_plur")
     1073            self.assertEqual(elem.text, "455 Resultate")
  • new file tests/regressiontests/i18n/urls.py

    diff --git a/tests/regressiontests/i18n/urls.py b/tests/regressiontests/i18n/urls.py
    new file mode 100644
    index 0000000..ec5e361
    - +  
     1from django.conf.urls import patterns
     2from django.views.generic import TemplateView
     3
     4
     5urlpatterns = patterns('',
     6    (r'^javascript_i18n/$', TemplateView.as_view(template_name='javascript_i18n.html')),
     7    (r'^jsi18n/$', 'django.views.i18n.javascript_catalog',
     8        {'packages': ('django.contrib.admin','regressiontests.i18n.other'),}
     9    ),
     10)
Back to Top