1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Refs #20888 -- Added index order introspection.

This commit is contained in:
Akshesh
2016-07-26 06:34:28 +05:30
committed by Tim Graham
parent 5eab1f6f83
commit f842d1011c
8 changed files with 78 additions and 16 deletions

View File

@@ -182,6 +182,26 @@ class IntrospectionTests(TransactionTestCase):
self.assertNotIn('first_name', indexes)
self.assertIn('id', indexes)
@skipUnlessDBFeature('supports_index_column_ordering')
def test_get_constraints_indexes_orders(self):
"""
Indexes have the 'orders' key with a list of 'ASC'/'DESC' values.
"""
with connection.cursor() as cursor:
constraints = connection.introspection.get_constraints(cursor, Article._meta.db_table)
indexes_verified = 0
expected_columns = [
['reporter_id'],
['headline', 'pub_date'],
['response_to_id'],
]
for key, val in constraints.items():
if val['index'] and not (val['primary_key'] or val['unique']):
self.assertIn(val['columns'], expected_columns)
self.assertEqual(val['orders'], ['ASC'] * len(val['columns']))
indexes_verified += 1
self.assertEqual(indexes_verified, 3)
def datatype(dbtype, description):
"""Helper to convert a data type into a string."""