|
2 | 2 | from io import StringIO |
3 | 3 | from unittest import mock, skipUnless |
4 | 4 |
|
5 | | -from django.core.management import call_command |
| 5 | +from django.core.management import CommandError, call_command |
6 | 6 | from django.core.management.commands import inspectdb |
7 | 7 | from django.db import connection |
8 | 8 | from django.db.backends.base.introspection import TableInfo |
9 | | -from django.test import TestCase, TransactionTestCase, skipUnlessDBFeature |
| 9 | +from django.test import ( |
| 10 | + TestCase, |
| 11 | + TransactionTestCase, |
| 12 | + skipIfDBFeature, |
| 13 | + skipUnlessDBFeature, |
| 14 | +) |
10 | 15 |
|
11 | 16 | from .models import PeopleMoreData, test_collation |
12 | 17 |
|
@@ -40,6 +45,7 @@ def cursor_execute(*queries): |
40 | 45 | return results |
41 | 46 |
|
42 | 47 |
|
| 48 | +@skipUnlessDBFeature("supports_inspectdb") |
43 | 49 | class InspectDBTestCase(TestCase): |
44 | 50 | unique_re = re.compile(r".*unique_together = \((.+),\).*") |
45 | 51 |
|
@@ -519,6 +525,7 @@ def test_same_relations(self): |
519 | 525 | ) |
520 | 526 |
|
521 | 527 |
|
| 528 | +@skipUnlessDBFeature("supports_inspectdb") |
522 | 529 | class InspectDBTransactionalTests(TransactionTestCase): |
523 | 530 | available_apps = ["inspectdb"] |
524 | 531 |
|
@@ -671,3 +678,14 @@ def test_composite_primary_key_not_unique_together(self): |
671 | 678 | out = StringIO() |
672 | 679 | call_command("inspectdb", "inspectdb_compositepkmodel", stdout=out) |
673 | 680 | self.assertNotIn("unique_together", out.getvalue()) |
| 681 | + |
| 682 | + |
| 683 | +@skipIfDBFeature("supports_inspectdb") |
| 684 | +class InspectDBNotSupportedTests(TestCase): |
| 685 | + def test_not_supported(self): |
| 686 | + msg = ( |
| 687 | + "Database inspection isn't supported for the currently selected " |
| 688 | + "database backend." |
| 689 | + ) |
| 690 | + with self.assertRaisesMessage(CommandError, msg): |
| 691 | + call_command("inspectdb") |
0 commit comments