summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Fursov <geyser85@gmail.com>2022-09-12 13:21:09 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-09-12 13:52:06 +0200
commit1b08e9bf7d88dbad9324f462e5fc7ec582aef3cc (patch)
tree5dc351a5d98b9697f5477f9aa7c985eb35a68aae
parent07ebef566f751e172e266165071081c7614e2d33 (diff)
Refs #31335 -- Added more tests for removing composed Meta constraints/indexes on foreign keys.
-rw-r--r--tests/schema/tests.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/schema/tests.py b/tests/schema/tests.py
index c31a1d78fa..941b28900e 100644
--- a/tests/schema/tests.py
+++ b/tests/schema/tests.py
@@ -2720,6 +2720,49 @@ class SchemaTests(TransactionTestCase):
with connection.schema_editor() as editor:
editor.alter_unique_together(Book, [["author", "title"]], [])
+ def _test_composed_index_with_fk(self, index):
+ with connection.schema_editor() as editor:
+ editor.create_model(Author)
+ editor.create_model(Book)
+ table = Book._meta.db_table
+ self.assertEqual(Book._meta.indexes, [])
+ Book._meta.indexes = [index]
+ with connection.schema_editor() as editor:
+ editor.add_index(Book, index)
+ self.assertIn(index.name, self.get_constraints(table))
+ Book._meta.indexes = []
+ with connection.schema_editor() as editor:
+ editor.remove_index(Book, index)
+ self.assertNotIn(index.name, self.get_constraints(table))
+
+ @skipUnlessDBFeature("supports_expression_indexes")
+ def test_composed_func_transform_index_with_fk(self):
+ index = Index(F("title__lower"), name="book_title_lower_idx")
+ with register_lookup(CharField, Lower):
+ self._test_composed_index_with_fk(index)
+
+ def _test_composed_constraint_with_fk(self, constraint):
+ with connection.schema_editor() as editor:
+ editor.create_model(Author)
+ editor.create_model(Book)
+ table = Book._meta.db_table
+ self.assertEqual(Book._meta.constraints, [])
+ Book._meta.constraints = [constraint]
+ with connection.schema_editor() as editor:
+ editor.add_constraint(Book, constraint)
+ self.assertIn(constraint.name, self.get_constraints(table))
+ Book._meta.constraints = []
+ with connection.schema_editor() as editor:
+ editor.remove_constraint(Book, constraint)
+ self.assertNotIn(constraint.name, self.get_constraints(table))
+
+ @skipUnlessDBFeature(
+ "supports_column_check_constraints", "can_introspect_check_constraints"
+ )
+ def test_composed_check_constraint_with_fk(self):
+ constraint = CheckConstraint(check=Q(author__gt=0), name="book_author_check")
+ self._test_composed_constraint_with_fk(constraint)
+
@skipUnlessDBFeature("allows_multiple_constraints_on_same_fields")
def test_remove_unique_together_does_not_remove_meta_constraints(self):
with connection.schema_editor() as editor: