From 226ca7b5ce283e1f891dbbbefb0afaebdaa09f28 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Tue, 23 Dec 2025 19:34:32 -0500 Subject: Added DatabaseFeatures.supports_inspectdb. Needed by MongoDB. --- tests/gis_tests/inspectapp/tests.py | 1 + tests/inspectdb/tests.py | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/gis_tests/inspectapp/tests.py b/tests/gis_tests/inspectapp/tests.py index 43227d232d..fd6fec32d9 100644 --- a/tests/gis_tests/inspectapp/tests.py +++ b/tests/gis_tests/inspectapp/tests.py @@ -14,6 +14,7 @@ from ..test_data import TEST_DATA from .models import AllOGRFields +@skipUnlessDBFeature("supports_inspectdb") class InspectDbTests(TestCase): def test_geom_columns(self): """ diff --git a/tests/inspectdb/tests.py b/tests/inspectdb/tests.py index 8175c52e4e..b677af23df 100644 --- a/tests/inspectdb/tests.py +++ b/tests/inspectdb/tests.py @@ -2,11 +2,16 @@ import re from io import StringIO from unittest import mock, skipUnless -from django.core.management import call_command +from django.core.management import CommandError, call_command from django.core.management.commands import inspectdb from django.db import connection from django.db.backends.base.introspection import TableInfo -from django.test import TestCase, TransactionTestCase, skipUnlessDBFeature +from django.test import ( + TestCase, + TransactionTestCase, + skipIfDBFeature, + skipUnlessDBFeature, +) from .models import PeopleMoreData, test_collation @@ -40,6 +45,7 @@ def cursor_execute(*queries): return results +@skipUnlessDBFeature("supports_inspectdb") class InspectDBTestCase(TestCase): unique_re = re.compile(r".*unique_together = \((.+),\).*") @@ -519,6 +525,7 @@ class InspectDBTestCase(TestCase): ) +@skipUnlessDBFeature("supports_inspectdb") class InspectDBTransactionalTests(TransactionTestCase): available_apps = ["inspectdb"] @@ -671,3 +678,14 @@ class InspectDBTransactionalTests(TransactionTestCase): out = StringIO() call_command("inspectdb", "inspectdb_compositepkmodel", stdout=out) self.assertNotIn("unique_together", out.getvalue()) + + +@skipIfDBFeature("supports_inspectdb") +class InspectDBNotSupportedTests(TestCase): + def test_not_supported(self): + msg = ( + "Database inspection isn't supported for the currently selected " + "database backend." + ) + with self.assertRaisesMessage(CommandError, msg): + call_command("inspectdb") -- cgit v1.3