|
@@ -6,6 +6,7 @@ from admin_scripts.tests import AdminScriptTestCase
|
|
|
|
|
|
from django.apps import apps
|
|
|
from django.core import management
|
|
|
+from django.core.checks import Tags
|
|
|
from django.core.management import BaseCommand, CommandError, find_commands
|
|
|
from django.core.management.utils import (
|
|
|
find_command, get_random_secret_key, is_ignored_path,
|
|
@@ -13,8 +14,9 @@ from django.core.management.utils import (
|
|
|
)
|
|
|
from django.db import connection
|
|
|
from django.test import SimpleTestCase, override_settings
|
|
|
-from django.test.utils import captured_stderr, extend_sys_path
|
|
|
+from django.test.utils import captured_stderr, extend_sys_path, ignore_warnings
|
|
|
from django.utils import translation
|
|
|
+from django.utils.deprecation import RemovedInDjango41Warning
|
|
|
from django.utils.version import PY37
|
|
|
|
|
|
from .management.commands import dance
|
|
@@ -59,13 +61,13 @@ class CommandTests(SimpleTestCase):
|
|
|
with self.assertRaises(CommandError) as cm:
|
|
|
management.call_command('dance', example="raise")
|
|
|
self.assertEqual(cm.exception.returncode, 3)
|
|
|
- dance.Command.requires_system_checks = False
|
|
|
+ dance.Command.requires_system_checks = []
|
|
|
try:
|
|
|
with captured_stderr() as stderr, self.assertRaises(SystemExit) as cm:
|
|
|
management.ManagementUtility(['manage.py', 'dance', '--example=raise']).execute()
|
|
|
self.assertEqual(cm.exception.code, 3)
|
|
|
finally:
|
|
|
- dance.Command.requires_system_checks = True
|
|
|
+ dance.Command.requires_system_checks = '__all__'
|
|
|
self.assertIn("CommandError", stderr.getvalue())
|
|
|
|
|
|
def test_no_translations_deactivate_translations(self):
|
|
@@ -155,6 +157,7 @@ class CommandTests(SimpleTestCase):
|
|
|
|
|
|
def patched_check(self_, **kwargs):
|
|
|
self.counter += 1
|
|
|
+ self.kwargs = kwargs
|
|
|
|
|
|
saved_check = BaseCommand.check
|
|
|
BaseCommand.check = patched_check
|
|
@@ -163,9 +166,28 @@ class CommandTests(SimpleTestCase):
|
|
|
self.assertEqual(self.counter, 0)
|
|
|
management.call_command("dance", verbosity=0, skip_checks=False)
|
|
|
self.assertEqual(self.counter, 1)
|
|
|
+ self.assertEqual(self.kwargs, {})
|
|
|
finally:
|
|
|
BaseCommand.check = saved_check
|
|
|
|
|
|
+ def test_requires_system_checks_empty(self):
|
|
|
+ with mock.patch('django.core.management.base.BaseCommand.check') as mocked_check:
|
|
|
+ management.call_command('no_system_checks')
|
|
|
+ self.assertIs(mocked_check.called, False)
|
|
|
+
|
|
|
+ def test_requires_system_checks_specific(self):
|
|
|
+ with mock.patch('django.core.management.base.BaseCommand.check') as mocked_check:
|
|
|
+ management.call_command('specific_system_checks')
|
|
|
+ mocked_check.called_once_with(tags=[Tags.staticfiles, Tags.models])
|
|
|
+
|
|
|
+ def test_requires_system_checks_invalid(self):
|
|
|
+ class Command(BaseCommand):
|
|
|
+ requires_system_checks = 'x'
|
|
|
+
|
|
|
+ msg = 'requires_system_checks must be a list or tuple.'
|
|
|
+ with self.assertRaisesMessage(TypeError, msg):
|
|
|
+ Command()
|
|
|
+
|
|
|
def test_check_migrations(self):
|
|
|
requires_migrations_checks = dance.Command.requires_migrations_checks
|
|
|
self.assertIs(requires_migrations_checks, False)
|
|
@@ -334,3 +356,45 @@ class UtilsTests(SimpleTestCase):
|
|
|
def test_normalize_path_patterns_truncates_wildcard_base(self):
|
|
|
expected = [os.path.normcase(p) for p in ['foo/bar', 'bar/*/']]
|
|
|
self.assertEqual(normalize_path_patterns(['foo/bar/*', 'bar/*/']), expected)
|
|
|
+
|
|
|
+
|
|
|
+class DeprecationTests(SimpleTestCase):
|
|
|
+ def test_requires_system_checks_warning(self):
|
|
|
+ class Command(BaseCommand):
|
|
|
+ pass
|
|
|
+
|
|
|
+ msg = (
|
|
|
+ "Using a boolean value for requires_system_checks is deprecated. "
|
|
|
+ "Use '__all__' instead of True, and [] (an empty list) instead of "
|
|
|
+ "False."
|
|
|
+ )
|
|
|
+ for value in [False, True]:
|
|
|
+ Command.requires_system_checks = value
|
|
|
+ with self.assertRaisesMessage(RemovedInDjango41Warning, msg):
|
|
|
+ Command()
|
|
|
+
|
|
|
+ @ignore_warnings(category=RemovedInDjango41Warning)
|
|
|
+ def test_requires_system_checks_true(self):
|
|
|
+ class Command(BaseCommand):
|
|
|
+ requires_system_checks = True
|
|
|
+
|
|
|
+ def handle(self, *args, **options):
|
|
|
+ pass
|
|
|
+
|
|
|
+ command = Command()
|
|
|
+ with mock.patch('django.core.management.base.BaseCommand.check') as mocked_check:
|
|
|
+ management.call_command(command, skip_checks=False)
|
|
|
+ mocked_check.assert_called_once_with()
|
|
|
+
|
|
|
+ @ignore_warnings(category=RemovedInDjango41Warning)
|
|
|
+ def test_requires_system_checks_false(self):
|
|
|
+ class Command(BaseCommand):
|
|
|
+ requires_system_checks = False
|
|
|
+
|
|
|
+ def handle(self, *args, **options):
|
|
|
+ pass
|
|
|
+
|
|
|
+ command = Command()
|
|
|
+ with mock.patch('django.core.management.base.BaseCommand.check') as mocked_check:
|
|
|
+ management.call_command(command)
|
|
|
+ self.assertIs(mocked_check.called, False)
|