summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAkshesh <aksheshdoshi@gmail.com>2016-07-22 18:22:44 +0530
committerTim Graham <timograham@gmail.com>2016-08-12 15:52:16 -0400
commit311a8e8d505049ff5644a94e16c00246c8a43a18 (patch)
treeb1414effbd64ec472f64e3484b63d20d4b554526 /tests
parent6b842c599865217529d835c0e20e881b98104295 (diff)
Fixed #20888 -- Added support for column order in class-based indexes.
Diffstat (limited to 'tests')
-rw-r--r--tests/model_indexes/tests.py5
-rw-r--r--tests/schema/tests.py24
2 files changed, 29 insertions, 0 deletions
diff --git a/tests/model_indexes/tests.py b/tests/model_indexes/tests.py
index b3f5d04dc1..52db494905 100644
--- a/tests/model_indexes/tests.py
+++ b/tests/model_indexes/tests.py
@@ -46,6 +46,11 @@ class IndexesTests(TestCase):
index.set_name_with_model(Book)
self.assertEqual(index.name, 'model_index_author_0f5565_idx')
+ # '-' for DESC columns should be accounted for in the index name.
+ index = models.Index(fields=['-author'])
+ index.set_name_with_model(Book)
+ self.assertEqual(index.name, 'model_index_author_708765_idx')
+
# fields may be truncated in the name. db_column is used for naming.
long_field_index = models.Index(fields=['pages'])
long_field_index.set_name_with_model(Book)
diff --git a/tests/schema/tests.py b/tests/schema/tests.py
index 6bb4aa6f8f..9622a443a9 100644
--- a/tests/schema/tests.py
+++ b/tests/schema/tests.py
@@ -156,6 +156,12 @@ class SchemaTests(TransactionTestCase):
counts['indexes'] += 1
return counts
+ def assertIndexOrder(self, table, index, order):
+ constraints = self.get_constraints(table)
+ self.assertIn(index, constraints)
+ index_orders = constraints[index]['orders']
+ self.assertTrue(all([(val == expected) for val, expected in zip(index_orders, order)]))
+
# Tests
def test_creation_deletion(self):
"""
@@ -1597,6 +1603,24 @@ class SchemaTests(TransactionTestCase):
editor.remove_index(Author, index)
self.assertNotIn('name', self.get_indexes(Author._meta.db_table))
+ def test_order_index(self):
+ """
+ Indexes defined with ordering (ASC/DESC) defined on column
+ """
+ with connection.schema_editor() as editor:
+ editor.create_model(Author)
+ # The table doesn't have an index
+ self.assertNotIn('title', self.get_indexes(Author._meta.db_table))
+ index_name = 'author_name_idx'
+ # Add the index
+ index = Index(fields=['name', '-weight'], name=index_name)
+ with connection.schema_editor() as editor:
+ editor.add_index(Author, index)
+ if connection.features.supports_index_column_ordering:
+ if connection.features.uppercases_column_names:
+ index_name = index_name.upper()
+ self.assertIndexOrder(Author._meta.db_table, index_name, ['ASC', 'DESC'])
+
def test_indexes(self):
"""
Tests creation/altering of indexes