diff options
| author | Ramiro Morales <cramm0@gmail.com> | 2013-02-03 20:53:48 -0300 |
|---|---|---|
| committer | Ramiro Morales <cramm0@gmail.com> | 2013-02-03 23:40:38 -0300 |
| commit | 869c9ba30615cb24fb5786787a2db8655f2f0d2b (patch) | |
| tree | 58051b8ce8ab9531a64e241798b7703cc450736b /tests | |
| parent | 2c173ff3b45e0a123147e3633082bbf9a7624536 (diff) | |
Fixed #19730 -- Don't validate importability of settings by using i18n in management commands.
They are handled independently now and the latter can be influenced by
the new BaseCommand.leave_locale_alone internal option.
Thanks chrischambers for the report, Claude, lpiatek, neaf and gabooo for
their work on a patch, originally on refs. #17379.
Diffstat (limited to 'tests')
4 files changed, 39 insertions, 0 deletions
diff --git a/tests/modeltests/user_commands/management/commands/leave_locale_alone_false.py b/tests/modeltests/user_commands/management/commands/leave_locale_alone_false.py new file mode 100644 index 0000000000..8ebb607d5a --- /dev/null +++ b/tests/modeltests/user_commands/management/commands/leave_locale_alone_false.py @@ -0,0 +1,10 @@ +from django.core.management.base import BaseCommand +from django.utils import translation + +class Command(BaseCommand): + + can_import_settings = True + leave_locale_alone = False + + def handle(self, *args, **options): + return translation.get_language() diff --git a/tests/modeltests/user_commands/management/commands/leave_locale_alone_true.py b/tests/modeltests/user_commands/management/commands/leave_locale_alone_true.py new file mode 100644 index 0000000000..e0f923591e --- /dev/null +++ b/tests/modeltests/user_commands/management/commands/leave_locale_alone_true.py @@ -0,0 +1,10 @@ +from django.core.management.base import BaseCommand +from django.utils import translation + +class Command(BaseCommand): + + can_import_settings = True + leave_locale_alone = True + + def handle(self, *args, **options): + return translation.get_language() diff --git a/tests/modeltests/user_commands/tests.py b/tests/modeltests/user_commands/tests.py index d25911c09f..c8740577a5 100644 --- a/tests/modeltests/user_commands/tests.py +++ b/tests/modeltests/user_commands/tests.py @@ -44,3 +44,17 @@ class CommandTests(TestCase): finally: sys.stderr = old_stderr self.assertIn("CommandError", err.getvalue()) + + def test_default_en_us_locale_set(self): + # Forces en_us when set to true + out = StringIO() + with translation.override('pl'): + management.call_command('leave_locale_alone_false', stdout=out) + self.assertEqual(out.getvalue(), "en-us\n") + + def test_configured_locale_preserved(self): + # Leaves locale from settings when set to false + out = StringIO() + with translation.override('pl'): + management.call_command('leave_locale_alone_true', stdout=out) + self.assertEqual(out.getvalue(), "pl\n") diff --git a/tests/regressiontests/i18n/commands/extraction.py b/tests/regressiontests/i18n/commands/extraction.py index 0367d23ec6..ca89f30de8 100644 --- a/tests/regressiontests/i18n/commands/extraction.py +++ b/tests/regressiontests/i18n/commands/extraction.py @@ -110,6 +110,11 @@ class BasicExtractorTests(ExtractorTests): self.assertMsgId('I think that 100%% is more that 50%% of %(obj)s.', po_contents) self.assertMsgId("Blocktrans extraction shouldn't double escape this: %%, a=%(a)s", po_contents) + def test_force_en_us_locale(self): + """Value of locale-munging option used by the command is the right one""" + from django.core.management.commands.makemessages import Command + self.assertTrue(Command.leave_locale_alone) + def test_extraction_error(self): os.chdir(self.test_dir) self.assertRaises(SyntaxError, management.call_command, 'makemessages', locale=LOCALE, extensions=['tpl'], verbosity=0) |
