1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

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>
This commit is contained in:
Jacob Walls
2024-11-23 11:41:14 -05:00
committed by Sarah Boyce
parent a16eedcf9c
commit 2ce4545de1
7 changed files with 114 additions and 24 deletions

View File

@@ -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):