diff options
author | David Wobrock <david.wobrock@gmail.com> | 2022-06-02 21:03:00 +0200 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-06-03 06:32:11 +0200 |
commit | a3a1290d47326c3f87824b3cf7ca969cb0d364aa (patch) | |
tree | 0956d8cf901c00e29c3ea1e626e10d15438769ae /tests/schema | |
parent | 61badf1d58e79b84874afa6a1e00b79f20e786d1 (diff) | |
download | django-a3a1290d47326c3f87824b3cf7ca969cb0d364aa.tar.gz |
Refs #27236 -- Moved models with Meta.index_together inside of test methods.
Diffstat (limited to 'tests/schema')
-rw-r--r-- | tests/schema/models.py | 18 | ||||
-rw-r--r-- | tests/schema/tests.py | 25 |
2 files changed, 21 insertions, 22 deletions
diff --git a/tests/schema/models.py b/tests/schema/models.py index 55f7d2c13c..75e32a0eab 100644 --- a/tests/schema/models.py +++ b/tests/schema/models.py @@ -62,15 +62,6 @@ class AuthorWithUniqueName(models.Model): apps = new_apps -class AuthorWithIndexedNameAndBirthday(models.Model): - name = models.CharField(max_length=255) - birthday = models.DateField() - - class Meta: - apps = new_apps - index_together = [["name", "birthday"]] - - class AuthorWithUniqueNameAndBirthday(models.Model): name = models.CharField(max_length=255) birthday = models.DateField() @@ -180,15 +171,6 @@ class Tag(models.Model): apps = new_apps -class TagIndexed(models.Model): - title = models.CharField(max_length=255) - slug = models.SlugField(unique=True) - - class Meta: - apps = new_apps - index_together = [["slug", "title"]] - - class TagM2MTest(models.Model): title = models.CharField(max_length=255) slug = models.SlugField(unique=True) diff --git a/tests/schema/tests.py b/tests/schema/tests.py index fe717f8841..7651b691b9 100644 --- a/tests/schema/tests.py +++ b/tests/schema/tests.py @@ -64,7 +64,6 @@ from .models import ( AuthorWithDefaultHeight, AuthorWithEvenLongerName, AuthorWithIndexedName, - AuthorWithIndexedNameAndBirthday, AuthorWithUniqueName, AuthorWithUniqueNameAndBirthday, Book, @@ -79,7 +78,6 @@ from .models import ( Note, NoteRename, Tag, - TagIndexed, TagM2MTest, TagUniqueRename, Thing, @@ -114,7 +112,6 @@ class SchemaTests(TransactionTestCase): Node, Note, Tag, - TagIndexed, TagM2MTest, TagUniqueRename, Thing, @@ -2952,13 +2949,24 @@ class SchemaTests(TransactionTestCase): with connection.schema_editor() as editor: editor.alter_index_together(Book, [["author", "title"]], []) + @isolate_apps("schema") def test_create_index_together(self): """ Tests creating models with index_together already defined """ + + class TagIndexed(Model): + title = CharField(max_length=255) + slug = SlugField(unique=True) + + class Meta: + app_label = "schema" + index_together = [["slug", "title"]] + # Create the table with connection.schema_editor() as editor: editor.create_model(TagIndexed) + self.isolated_local_models = [TagIndexed] # Ensure there is an index self.assertIs( any( @@ -2970,10 +2978,19 @@ class SchemaTests(TransactionTestCase): ) @skipUnlessDBFeature("allows_multiple_constraints_on_same_fields") + @isolate_apps("schema") def test_remove_index_together_does_not_remove_meta_indexes(self): + class AuthorWithIndexedNameAndBirthday(Model): + name = CharField(max_length=255) + birthday = DateField() + + class Meta: + app_label = "schema" + index_together = [["name", "birthday"]] + with connection.schema_editor() as editor: editor.create_model(AuthorWithIndexedNameAndBirthday) - self.local_models = [AuthorWithIndexedNameAndBirthday] + self.isolated_local_models = [AuthorWithIndexedNameAndBirthday] # Add the custom index index = Index(fields=["name", "birthday"], name="author_name_birthday_idx") custom_index_name = index.name |