summaryrefslogtreecommitdiff
path: root/tests/schema
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2020-10-20 00:22:56 -0400
committerGitHub <noreply@github.com>2020-10-20 06:22:56 +0200
commitede9fac75807fe5810df66280a60e7068cc97e4a (patch)
tree7714702d183476480749012a8ddd795689947bc3 /tests/schema
parentc897b1587cb8017b6c943bf6486286655b0d9e3d (diff)
Fixed #32120 -- Added DatabaseFeatures.indexes_foreign_keys.
Diffstat (limited to 'tests/schema')
-rw-r--r--tests/schema/tests.py33
1 files changed, 27 insertions, 6 deletions
diff --git a/tests/schema/tests.py b/tests/schema/tests.py
index e41db7a500..a7743deba4 100644
--- a/tests/schema/tests.py
+++ b/tests/schema/tests.py
@@ -292,7 +292,12 @@ class SchemaTests(TransactionTestCase):
with connection.schema_editor() as editor:
editor.add_field(Node, new_field)
editor.execute('UPDATE schema_node SET new_parent_fk_id = %s;', [parent.pk])
- self.assertIn('new_parent_fk_id', self.get_indexes(Node._meta.db_table))
+ assertIndex = (
+ self.assertIn
+ if connection.features.indexes_foreign_keys
+ else self.assertNotIn
+ )
+ assertIndex('new_parent_fk_id', self.get_indexes(Node._meta.db_table))
@skipUnlessDBFeature(
'can_create_inline_fk',
@@ -316,7 +321,12 @@ class SchemaTests(TransactionTestCase):
Node._meta.add_field(new_field)
editor.execute('UPDATE schema_node SET new_parent_fk_id = %s;', [parent.pk])
editor.add_index(Node, Index(fields=['new_parent_fk'], name='new_parent_inline_fk_idx'))
- self.assertIn('new_parent_fk_id', self.get_indexes(Node._meta.db_table))
+ assertIndex = (
+ self.assertIn
+ if connection.features.indexes_foreign_keys
+ else self.assertNotIn
+ )
+ assertIndex('new_parent_fk_id', self.get_indexes(Node._meta.db_table))
@skipUnlessDBFeature('supports_foreign_keys')
def test_char_field_with_db_index_to_fk(self):
@@ -1161,6 +1171,7 @@ class SchemaTests(TransactionTestCase):
editor.create_model(Author)
editor.create_model(Book)
expected_fks = 1 if connection.features.supports_foreign_keys else 0
+ expected_indexes = 1 if connection.features.indexes_foreign_keys else 0
# Check the index is right to begin with.
counts = self.get_constraints_count(
@@ -1168,7 +1179,10 @@ class SchemaTests(TransactionTestCase):
Book._meta.get_field('author').column,
(Author._meta.db_table, Author._meta.pk.column),
)
- self.assertEqual(counts, {'fks': expected_fks, 'uniques': 0, 'indexes': 1})
+ self.assertEqual(
+ counts,
+ {'fks': expected_fks, 'uniques': 0, 'indexes': expected_indexes},
+ )
old_field = Book._meta.get_field('author')
new_field = OneToOneField(Author, CASCADE)
@@ -1189,6 +1203,7 @@ class SchemaTests(TransactionTestCase):
editor.create_model(Author)
editor.create_model(Book)
expected_fks = 1 if connection.features.supports_foreign_keys else 0
+ expected_indexes = 1 if connection.features.indexes_foreign_keys else 0
# Check the index is right to begin with.
counts = self.get_constraints_count(
@@ -1196,7 +1211,10 @@ class SchemaTests(TransactionTestCase):
Book._meta.get_field('author').column,
(Author._meta.db_table, Author._meta.pk.column),
)
- self.assertEqual(counts, {'fks': expected_fks, 'uniques': 0, 'indexes': 1})
+ self.assertEqual(
+ counts,
+ {'fks': expected_fks, 'uniques': 0, 'indexes': expected_indexes},
+ )
old_field = Book._meta.get_field('author')
# on_delete changed from CASCADE.
@@ -1211,7 +1229,10 @@ class SchemaTests(TransactionTestCase):
(Author._meta.db_table, Author._meta.pk.column),
)
# The index remains.
- self.assertEqual(counts, {'fks': expected_fks, 'uniques': 0, 'indexes': 1})
+ self.assertEqual(
+ counts,
+ {'fks': expected_fks, 'uniques': 0, 'indexes': expected_indexes},
+ )
def test_alter_field_o2o_to_fk(self):
with connection.schema_editor() as editor:
@@ -2521,7 +2542,7 @@ class SchemaTests(TransactionTestCase):
with self.assertRaisesMessage(TransactionManagementError, message):
editor.execute(editor.sql_create_table % {'table': 'foo', 'definition': ''})
- @skipUnlessDBFeature('supports_foreign_keys')
+ @skipUnlessDBFeature('supports_foreign_keys', 'indexes_foreign_keys')
def test_foreign_key_index_long_names_regression(self):
"""
Regression test for #21497.