diff options
| author | Ramiro Morales <cramm0@gmail.com> | 2013-01-25 13:23:33 -0300 |
|---|---|---|
| committer | Ramiro Morales <cramm0@gmail.com> | 2013-01-25 13:23:33 -0300 |
| commit | 2babab0bb351ff7a13fd23795f5e926a9bf95d22 (patch) | |
| tree | dcdffc1d0964d88d71980b7bd07e4ced495e9300 /tests | |
| parent | b9c8bbf3726a1956be1db70ffd3bef04a2e5311a (diff) | |
Patch by Claude for #16084.
Diffstat (limited to 'tests')
5 files changed, 56 insertions, 1 deletions
diff --git a/tests/regressiontests/i18n/commands/extraction.py b/tests/regressiontests/i18n/commands/extraction.py index ef711ec1bb..8b2941c4d4 100644 --- a/tests/regressiontests/i18n/commands/extraction.py +++ b/tests/regressiontests/i18n/commands/extraction.py @@ -5,10 +5,13 @@ import os import re import shutil +from django.conf import settings from django.core import management from django.test import SimpleTestCase +from django.test.utils import override_settings from django.utils.encoding import force_text from django.utils._os import upath +from django.utils import six from django.utils.six import StringIO @@ -352,3 +355,44 @@ class MultipleLocaleExtractionTests(ExtractorTests): management.call_command('makemessages', locale='pt,de,ch', verbosity=0) self.assertTrue(os.path.exists(self.PO_FILE_PT)) self.assertTrue(os.path.exists(self.PO_FILE_DE)) + + +class CustomLayoutExtractionTests(ExtractorTests): + def setUp(self): + self._cwd = os.getcwd() + self.test_dir = os.path.join(os.path.dirname(upath(__file__)), 'project_dir') + + def test_no_locale_raises(self): + os.chdir(self.test_dir) + with six.assertRaisesRegex(self, management.CommandError, + "Unable to find a locale path to store translations for file"): + management.call_command('makemessages', locale=LOCALE, verbosity=0) + + @override_settings( + LOCALE_PATHS=(os.path.join(os.path.dirname(upath(__file__)), 'project_dir/project_locale'),) + ) + def test_project_locale_paths(self): + """ + Test that: + * translations for app containing locale folder are stored in that folder + * translations outside of that app are in LOCALE_PATHS[0] + """ + os.chdir(self.test_dir) + self.addCleanup(shutil.rmtree, os.path.join(settings.LOCALE_PATHS[0], LOCALE)) + self.addCleanup(shutil.rmtree, os.path.join(self.test_dir, 'app_with_locale/locale', LOCALE)) + + management.call_command('makemessages', locale=LOCALE, verbosity=0) + project_de_locale = os.path.join( + self.test_dir, 'project_locale/de/LC_MESSAGES/django.po',) + app_de_locale = os.path.join( + self.test_dir, 'app_with_locale/locale/de/LC_MESSAGES/django.po',) + self.assertTrue(os.path.exists(project_de_locale)) + self.assertTrue(os.path.exists(app_de_locale)) + + with open(project_de_locale, 'r') as fp: + po_contents = force_text(fp.read()) + self.assertMsgId('This app has no locale directory', po_contents) + self.assertMsgId('This is a project-level string', po_contents) + with open(app_de_locale, 'r') as fp: + po_contents = force_text(fp.read()) + self.assertMsgId('This app has a locale directory', po_contents) diff --git a/tests/regressiontests/i18n/commands/project_dir/__init__.py b/tests/regressiontests/i18n/commands/project_dir/__init__.py new file mode 100644 index 0000000000..9c6768e4ab --- /dev/null +++ b/tests/regressiontests/i18n/commands/project_dir/__init__.py @@ -0,0 +1,3 @@ +from django.utils.translation import ugettext as _ + +string = _("This is a project-level string") diff --git a/tests/regressiontests/i18n/commands/project_dir/app_no_locale/models.py b/tests/regressiontests/i18n/commands/project_dir/app_no_locale/models.py new file mode 100644 index 0000000000..adcb2ef173 --- /dev/null +++ b/tests/regressiontests/i18n/commands/project_dir/app_no_locale/models.py @@ -0,0 +1,4 @@ +from django.utils.translation import ugettext as _ + +string = _("This app has no locale directory") + diff --git a/tests/regressiontests/i18n/commands/project_dir/app_with_locale/models.py b/tests/regressiontests/i18n/commands/project_dir/app_with_locale/models.py new file mode 100644 index 0000000000..44037157a0 --- /dev/null +++ b/tests/regressiontests/i18n/commands/project_dir/app_with_locale/models.py @@ -0,0 +1,4 @@ +from django.utils.translation import ugettext as _ + +string = _("This app has a locale directory") + diff --git a/tests/regressiontests/i18n/tests.py b/tests/regressiontests/i18n/tests.py index d9843c228a..9f6e73dcd2 100644 --- a/tests/regressiontests/i18n/tests.py +++ b/tests/regressiontests/i18n/tests.py @@ -33,7 +33,7 @@ if can_run_extraction_tests: JavascriptExtractorTests, IgnoredExtractorTests, SymlinkExtractorTests, CopyPluralFormsExtractorTests, NoWrapExtractorTests, NoLocationExtractorTests, KeepPotFileExtractorTests, - MultipleLocaleExtractionTests) + MultipleLocaleExtractionTests, CustomLayoutExtractionTests) if can_run_compilation_tests: from .commands.compilation import (PoFileTests, PoFileContentsTests, PercentRenderingTests, MultipleLocaleCompilationTests) |
