summaryrefslogtreecommitdiff
path: root/tests/admin_scripts
diff options
context:
space:
mode:
authorJacob Walls <jacobtylerwalls@gmail.com>2024-11-23 11:41:14 -0500
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2024-12-11 17:25:47 +0100
commit2ce4545de1791d6ed2405cb0657401e179bc5357 (patch)
tree6c4a837bfd9e1b0f19e06edb50f7dd99ca2b575b /tests/admin_scripts
parenta16eedcf9c69d8a11d94cac1811018c5b996d491 (diff)
Fixed #35920 -- Observed requires_system_checks in migrate and runserver.
Before, the full suite of system checks was run by these commands regardless if requires_system_checks had been overridden. Co-authored-by: Simon Charette <charette.s@gmail.com>
Diffstat (limited to 'tests/admin_scripts')
-rw-r--r--tests/admin_scripts/tests.py52
1 files changed, 50 insertions, 2 deletions
diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py
index 3145723920..5d8a5ec97e 100644
--- a/tests/admin_scripts/tests.py
+++ b/tests/admin_scripts/tests.py
@@ -20,6 +20,8 @@ from user_commands.utils import AssertFormatterFailureCaughtContext
from django import conf, get_version
from django.conf import settings
+from django.core.checks import Error, Tags, register
+from django.core.checks.registry import registry
from django.core.management import (
BaseCommand,
CommandError,
@@ -27,7 +29,7 @@ from django.core.management import (
color,
execute_from_command_line,
)
-from django.core.management.base import LabelCommand
+from django.core.management.base import LabelCommand, SystemCheckError
from django.core.management.commands.loaddata import Command as LoaddataCommand
from django.core.management.commands.runserver import Command as RunserverCommand
from django.core.management.commands.testserver import Command as TestserverCommand
@@ -1733,7 +1735,53 @@ class ManageRunserver(SimpleTestCase):
stdout=self.output,
)
self.assertIn("Performing system checks...", self.output.getvalue())
- mocked_check.assert_called()
+ mocked_check.assert_has_calls(
+ [mock.call(tags=set()), mock.call(display_num_errors=True)]
+ )
+
+ def test_custom_system_checks(self):
+ original_checks = registry.registered_checks.copy()
+
+ @register(Tags.signals)
+ def my_check(app_configs, **kwargs):
+ return [Error("my error")]
+
+ class CustomException(Exception):
+ pass
+
+ self.addCleanup(setattr, registry, "registered_checks", original_checks)
+
+ class CustomRunserverCommand(RunserverCommand):
+ """Rather than mock run(), raise immediately after system checks run."""
+
+ def check_migrations(self, *args, **kwargs):
+ raise CustomException
+
+ class CustomRunserverCommandWithSignalsChecks(CustomRunserverCommand):
+ requires_system_checks = [Tags.signals]
+
+ command = CustomRunserverCommandWithSignalsChecks()
+ with self.assertRaises(SystemCheckError):
+ call_command(
+ command,
+ use_reloader=False,
+ skip_checks=False,
+ stdout=StringIO(),
+ stderr=StringIO(),
+ )
+
+ class CustomMigrateCommandWithSecurityChecks(CustomRunserverCommand):
+ requires_system_checks = [Tags.security]
+
+ command = CustomMigrateCommandWithSecurityChecks()
+ with self.assertRaises(CustomException):
+ call_command(
+ command,
+ use_reloader=False,
+ skip_checks=False,
+ stdout=StringIO(),
+ stderr=StringIO(),
+ )
class ManageRunserverMigrationWarning(TestCase):