summaryrefslogtreecommitdiff
path: root/tests/schema
diff options
context:
space:
mode:
authorAkshesh <aksheshdoshi@gmail.com>2016-06-25 22:02:56 +0530
committerTim Graham <timograham@gmail.com>2016-06-27 10:41:01 -0400
commit156e2d59cf92eb252c2f6ef9bb0b65f26c707de2 (patch)
treea385db97c67f6b8504954c3df3ac88f169d13f8c /tests/schema
parentc962b9104a22505a7d6c57bbec9eda163f486c7d (diff)
Fixed #26709 -- Added class-based indexes.
Added the AddIndex and RemoveIndex operations to use them in migrations. Thanks markush, mjtamlyn, timgraham, and charettes for review and advice.
Diffstat (limited to 'tests/schema')
-rw-r--r--tests/schema/tests.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/schema/tests.py b/tests/schema/tests.py
index 8b35b77c7b..a3e4f8227a 100644
--- a/tests/schema/tests.py
+++ b/tests/schema/tests.py
@@ -16,6 +16,7 @@ from django.db.models.fields import (
from django.db.models.fields.related import (
ForeignKey, ForeignObject, ManyToManyField, OneToOneField,
)
+from django.db.models.indexes import Index
from django.db.transaction import atomic
from django.test import (
TransactionTestCase, mock, skipIfDBFeature, skipUnlessDBFeature,
@@ -1443,6 +1444,26 @@ class SchemaTests(TransactionTestCase):
columns = self.column_classes(Author)
self.assertEqual(columns['name'][0], "CharField")
+ def test_add_remove_index(self):
+ """
+ Tests index addition and removal
+ """
+ # Create the table
+ with connection.schema_editor() as editor:
+ editor.create_model(Author)
+ # Ensure the table is there and has no index
+ self.assertNotIn('title', self.get_indexes(Author._meta.db_table))
+ # Add the index
+ index = Index(fields=['name'], name='author_title_idx')
+ index.model = Author
+ with connection.schema_editor() as editor:
+ editor.add_index(index)
+ self.assertIn('name', self.get_indexes(Author._meta.db_table))
+ # Drop the index
+ with connection.schema_editor() as editor:
+ editor.remove_index(index)
+ self.assertNotIn('name', self.get_indexes(Author._meta.db_table))
+
def test_indexes(self):
"""
Tests creation/altering of indexes