Ticket #13514: 13514-regression-test.diff

File 13514-regression-test.diff, 12.2 KB (added by ramiro, 5 years ago)

Patch with a regression test for this ticket. If/when applying don't forget to re-generate the .mo files

  • tests/regressiontests/admin_views/tests.py

    diff -r 84ec6befeb13 tests/regressiontests/admin_views/tests.py
    a b  
    22
    33import re
    44import datetime
    5 from django.conf import settings
    65from django.core.files import temp as tempfile
    76from django.test import TestCase
    87from django.contrib.auth import admin # Register auth models with the admin.
     
    1615from django.utils import formats
    1716from django.utils.cache import get_max_age
    1817from django.utils.html import escape
    19 from django.utils.translation import get_date_formats, activate, deactivate
    2018from django.utils.encoding import iri_to_uri
    2119
    2220# local test models
    2321from models import Article, BarAccount, CustomArticle, EmptyModel, \
    24     ExternalSubscriber, FooAccount, Gallery, ModelWithStringPrimaryKey, \
     22    FooAccount, Gallery, ModelWithStringPrimaryKey, \
    2523    Person, Persona, Picture, Podcast, Section, Subscriber, Vodcast, \
    2624    Language, Collector, Widget, Grommet, DooHickey, FancyDoodad, Whatsit, \
    2725    Category, Post, Plot, FunkyTag
     
    272270        response = self.client.get("/test_admin/admin/admin_views/post/")
    273271        self.failUnless('icon-unknown.gif' in response.content)
    274272
    275     def testI18NLanguageNonEnglishDefault(self):
    276         """
    277         Check if the Javascript i18n view returns an empty language catalog
    278         if the default language is non-English but the selected language
    279         is English. See #13388 and #3594 for more details.
    280         """
    281         old_language_code = settings.LANGUAGE_CODE
    282         settings.LANGUAGE_CODE = 'fr'
    283         activate('en-us')
    284         response = self.client.get('/test_admin/admin/jsi18n/')
    285         self.assertNotContains(response, 'Choisir une heure')
    286         deactivate()
    287         settings.LANGUAGE_CODE = old_language_code
    288 
    289     def testI18NLanguageNonEnglishFallback(self):
    290         """
    291         Makes sure that the fallback language is still working properly
    292         in cases where the selected language cannot be found.
    293         """
    294         old_language_code = settings.LANGUAGE_CODE
    295         settings.LANGUAGE_CODE = 'fr'
    296         activate('none')
    297         response = self.client.get('/test_admin/admin/jsi18n/')
    298         self.assertContains(response, 'Choisir une heure')
    299         deactivate()
    300         settings.LANGUAGE_CODE = old_language_code
    301 
    302273
    303274class SaveAsTests(TestCase):
    304275    fixtures = ['admin-views-users.xml','admin-views-person.xml']
  • new file tests/regressiontests/views/app1/__init__.py

    diff -r 84ec6befeb13 tests/regressiontests/views/app1/__init__.py
    - +  
     1#
  • new file tests/regressiontests/views/app1/locale/fr/LC_MESSAGES/djangojs.po

    diff -r 84ec6befeb13 tests/regressiontests/views/app1/locale/fr/LC_MESSAGES/djangojs.mo
    Binary file tests/regressiontests/views/app1/locale/fr/LC_MESSAGES/djangojs.mo has changed
    diff -r 84ec6befeb13 tests/regressiontests/views/app1/locale/fr/LC_MESSAGES/djangojs.po
    - +  
     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#
     6#, fuzzy
     7msgid ""
     8msgstr ""
     9"Project-Id-Version: PACKAGE VERSION\n"
     10"Report-Msgid-Bugs-To: \n"
     11"POT-Creation-Date: 2007-09-15 19:15+0200\n"
     12"PO-Revision-Date: 2010-05-12 12:41-0300\n"
     13"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
     14"Language-Team: LANGUAGE <LL@li.org>\n"
     15"MIME-Version: 1.0\n"
     16"Content-Type: text/plain; charset=UTF-8\n"
     17"Content-Transfer-Encoding: 8bit\n"
     18
     19msgid "this app1 string is to be translated"
     20msgstr "il faut traduire cette chaîne de caractères de app1"
  • new file tests/regressiontests/views/app2/__init__.py

    diff -r 84ec6befeb13 tests/regressiontests/views/app2/__init__.py
    - +  
     1#
  • new file tests/regressiontests/views/app2/locale/fr/LC_MESSAGES/djangojs.po

    diff -r 84ec6befeb13 tests/regressiontests/views/app2/locale/fr/LC_MESSAGES/djangojs.mo
    Binary file tests/regressiontests/views/app2/locale/fr/LC_MESSAGES/djangojs.mo has changed
    diff -r 84ec6befeb13 tests/regressiontests/views/app2/locale/fr/LC_MESSAGES/djangojs.po
    - +  
     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#
     6#, fuzzy
     7msgid ""
     8msgstr ""
     9"Project-Id-Version: PACKAGE VERSION\n"
     10"Report-Msgid-Bugs-To: \n"
     11"POT-Creation-Date: 2007-09-15 19:15+0200\n"
     12"PO-Revision-Date: 2010-05-12 12:41-0300\n"
     13"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
     14"Language-Team: LANGUAGE <LL@li.org>\n"
     15"MIME-Version: 1.0\n"
     16"Content-Type: text/plain; charset=UTF-8\n"
     17"Content-Transfer-Encoding: 8bit\n"
     18
     19msgid "this app2 string is to be translated"
     20msgstr "il faut traduire cette chaîne de caractères de app1"
  • tests/regressiontests/views/locale/es/LC_MESSAGES/djangojs.po

    diff -r 84ec6befeb13 tests/regressiontests/views/locale/es/LC_MESSAGES/djangojs.mo
    Binary file tests/regressiontests/views/locale/es/LC_MESSAGES/djangojs.mo has changed
    diff -r 84ec6befeb13 tests/regressiontests/views/locale/es/LC_MESSAGES/djangojs.po
    a b  
    99"Project-Id-Version: PACKAGE VERSION\n"
    1010"Report-Msgid-Bugs-To: \n"
    1111"POT-Creation-Date: 2007-09-15 16:45+0200\n"
    12 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
     12"PO-Revision-Date: 2010-05-12 12:57-0300\n"
    1313"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
    1414"Language-Team: LANGUAGE <LL@li.org>\n"
    1515"MIME-Version: 1.0\n"
     
    1818
    1919#: media/js/translate.js:1
    2020msgid "this is to be translated"
    21 msgstr "esto tiene que ser traducido"
    22  No newline at end of file
     21msgstr "esto tiene que ser traducido"
     22
     23
     24msgid "Choose a time"
     25msgstr "Elige una hora"
  • tests/regressiontests/views/locale/fr/LC_MESSAGES/djangojs.po

    diff -r 84ec6befeb13 tests/regressiontests/views/locale/fr/LC_MESSAGES/djangojs.mo
    Binary file tests/regressiontests/views/locale/fr/LC_MESSAGES/djangojs.mo has changed
    diff -r 84ec6befeb13 tests/regressiontests/views/locale/fr/LC_MESSAGES/djangojs.po
    a b  
    99"Project-Id-Version: PACKAGE VERSION\n"
    1010"Report-Msgid-Bugs-To: \n"
    1111"POT-Creation-Date: 2007-09-15 19:15+0200\n"
    12 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
     12"PO-Revision-Date: 2010-05-12 12:41-0300\n"
    1313"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
    1414"Language-Team: LANGUAGE <LL@li.org>\n"
    1515"MIME-Version: 1.0\n"
     
    1717"Content-Transfer-Encoding: 8bit\n"
    1818
    1919msgid "this is to be translated"
    20 msgstr "il faut le traduire"
    21  No newline at end of file
     20msgstr "il faut le traduire"
     21
     22
     23msgid "Choose a time"
     24msgstr "Choisir une heure"
  • tests/regressiontests/views/locale/ru/LC_MESSAGES/djangojs.po

    diff -r 84ec6befeb13 tests/regressiontests/views/locale/ru/LC_MESSAGES/djangojs.mo
    Binary file tests/regressiontests/views/locale/ru/LC_MESSAGES/djangojs.mo has changed
    diff -r 84ec6befeb13 tests/regressiontests/views/locale/ru/LC_MESSAGES/djangojs.po
    a b  
    99"Project-Id-Version: PACKAGE VERSION\n"
    1010"Report-Msgid-Bugs-To: \n"
    1111"POT-Creation-Date: 2007-09-15 16:45+0200\n"
    12 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
     12"PO-Revision-Date: 2010-05-12 12:57-0300\n"
    1313"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
    1414"Language-Team: LANGUAGE <LL@li.org>\n"
    1515"MIME-Version: 1.0\n"
     
    1717"Content-Transfer-Encoding: 8bit\n"
    1818
    1919msgid "this is to be translated"
    20 msgstr "перевод"
    21  No newline at end of file
     20msgstr "перевод"
     21
     22
     23msgid "Choose a time"
     24msgstr "Выберите время"
  • tests/regressiontests/views/tests/i18n.py

    diff -r 84ec6befeb13 tests/regressiontests/views/tests/i18n.py
    a b  
     1# -*- coding:utf-8 -*-
    12import gettext
    23
    34from django.conf import settings
    45from django.test import TestCase
    5 from django.utils.translation import activate
     6from django.utils.translation import activate, deactivate
    67from django.utils.text import javascript_quote
    78
    89from regressiontests.views.urls import locale_dir
     
    3031            # javascript_quote is used to be able to check unicode strings
    3132            self.assertContains(response, javascript_quote(trans_txt), 1)
    3233
     34
    3335class JsI18NTests(TestCase):
    3436    """
    3537    Tests django views in django/views/i18n.py that need to change
     
    6668        activate('fi')
    6769        response = self.client.get('/views/jsi18n/')
    6870        self.assertContains(response, 'il faut le traduire')
     71
     72    def testI18NLanguageNonEnglishDefault(self):
     73        """
     74        Check if the Javascript i18n view returns an empty language catalog
     75        if the default language is non-English but the selected language
     76        is English. See #13388 and #3594 for more details.
     77        """
     78        settings.LANGUAGE_CODE = 'fr'
     79        activate('en-us')
     80        response = self.client.get('/views/jsi18n/')
     81        self.assertNotContains(response, 'Choisir une heure')
     82        deactivate()
     83
     84    def testI18NLanguageNonEnglishFallback(self):
     85        """
     86        Makes sure that the fallback language is still working properly
     87        in cases where the selected language cannot be found.
     88        """
     89        settings.LANGUAGE_CODE = 'fr'
     90        activate('none')
     91        response = self.client.get('/views/jsi18n/')
     92        self.assertContains(response, 'Choisir une heure')
     93        deactivate()
     94
     95
     96class JsI18NTestsMultiPackage(TestCase):
     97    """
     98    Tests for django views in django/views/i18n.py that need to change
     99    settings.LANGUAGE_CODE and merge JS translation from several packages.
     100    """
     101    VIEW_PATH = '/views/jsi18n_multiple_packages/'
     102
     103    def setUp(self):
     104        self.old_language_code = settings.LANGUAGE_CODE
     105        self.old_installed_apps = settings.INSTALLED_APPS
     106        settings.INSTALLED_APPS = list(settings.INSTALLED_APPS) + ['regressiontests.views.app1', 'regressiontests.views.app2']
     107
     108    def tearDown(self):
     109        settings.LANGUAGE_CODE = self.old_language_code
     110        settings.INSTALLED_APPS = self.old_installed_apps
     111
     112    def testI18NLanguageNonEnglishDefault(self):
     113        """
     114        Check if the Javascript i18n view returns a complete language catalog
     115        if the default language is en-us, the selected language is available
     116        and a catalog composed by djangojs domain translations of multiple
     117        Python packages is requested. See #13388, #3594 and #13514 for more details.
     118        """
     119        settings.LANGUAGE_CODE = 'en-us'
     120        activate('fr')
     121        response = self.client.get(self.VIEW_PATH)
     122        #print response.content
     123        self.assertContains(response, 'il faut traduire cette chaîne de caractères de app1')
     124        deactivate()
  • tests/regressiontests/views/urls.py

    diff -r 84ec6befeb13 tests/regressiontests/views/urls.py
    a b  
    1616    'packages': ('regressiontests.views',),
    1717}
    1818
     19js_info_dict_multiple_packages = {
     20    'domain': 'djangojs',
     21    'packages': ('regressiontests.views', 'regressiontests.views.app1', 'regressiontests.views.app2'),
     22}
     23
    1924date_based_info_dict = {
    2025    'queryset': Article.objects.all(),
    2126    'date_field': 'date_created',
     
    3641    # i18n views
    3742    (r'^i18n/', include('django.conf.urls.i18n')),
    3843    (r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict),
     44    (r'^jsi18n_multiple_packages/$', 'django.views.i18n.javascript_catalog', js_info_dict_multiple_packages),
    3945
    4046    # Static views
    4147    (r'^site_media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': media_dir}),
Back to Top