diff options
| author | Simon Charette <charette.s@gmail.com> | 2025-11-08 15:26:36 -0500 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2025-11-13 10:18:06 +0100 |
| commit | 1b539ef27e776bd6112e8f22e653feca5279c4fb (patch) | |
| tree | 3c8b99a28bcc5426eb119b6d52e417fc0c3eb5e1 | |
| parent | abfa4619fb818ff694c22e962a280673e085239e (diff) | |
Refs #31055 -- Augmented regression tests for database system checks.
We might want to change this in the future but it should be further
discussed first.
| -rw-r--r-- | tests/check_framework/tests.py | 16 | ||||
| -rw-r--r-- | tests/migrations/test_commands.py | 21 |
2 files changed, 34 insertions, 3 deletions
diff --git a/tests/check_framework/tests.py b/tests/check_framework/tests.py index f926308fd7..c5f53c4789 100644 --- a/tests/check_framework/tests.py +++ b/tests/check_framework/tests.py @@ -1,11 +1,11 @@ import multiprocessing import sys from io import StringIO -from unittest import skipIf +from unittest import mock, skipIf from django.apps import apps from django.core import checks -from django.core.checks import Error, Warning +from django.core.checks import Error, Tags, Warning from django.core.checks.messages import CheckMessage from django.core.checks.registry import CheckRegistry from django.core.management import call_command @@ -268,6 +268,18 @@ class CheckCommandTests(SimpleTestCase): with self.assertRaises(CommandError): call_command("check", fail_level="WARNING") + def test_database_system_checks(self): + database_check = mock.Mock(return_value=[], tags=[Tags.database]) + + with override_system_checks([database_check]): + call_command("check") + database_check.assert_called_once_with(app_configs=None, databases=None) + database_check.reset_mock() + call_command("check", databases=["default"]) + database_check.assert_called_once_with( + app_configs=None, databases=["default"] + ) + def custom_error_system_check(app_configs, **kwargs): return [Error("Error", id="myerrorcheck.E001")] diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py index b5817081d2..83c5575fd3 100644 --- a/tests/migrations/test_commands.py +++ b/tests/migrations/test_commands.py @@ -113,7 +113,7 @@ class MigrateTests(MigrationTestBase): out = io.StringIO() call_command("migrate", skip_checks=False, no_color=True, stdout=out) self.assertIn("Apply all migrations: migrated_app", out.getvalue()) - mocked_check.assert_called_once() + mocked_check.assert_called_once_with(databases=["default"]) def test_migrate_with_custom_system_checks(self): original_checks = registry.registered_checks.copy() @@ -139,6 +139,25 @@ class MigrateTests(MigrationTestBase): @override_settings( INSTALLED_APPS=[ + "django.contrib.auth", + "django.contrib.contenttypes", + "migrations.migrations_test_apps.migrated_app", + ] + ) + def test_migrate_runs_database_system_checks(self): + original_checks = registry.registered_checks.copy() + self.addCleanup(setattr, registry, "registered_checks", original_checks) + + out = io.StringIO() + mock_check = mock.Mock(return_value=[]) + register(mock_check, Tags.database) + + call_command("migrate", skip_checks=False, no_color=True, stdout=out) + self.assertIn("Apply all migrations: migrated_app", out.getvalue()) + mock_check.assert_called_once_with(app_configs=None, databases=["default"]) + + @override_settings( + INSTALLED_APPS=[ "migrations", "migrations.migrations_test_apps.unmigrated_app_syncdb", ] |
