summaryrefslogtreecommitdiff
path: root/tests/indexes
diff options
context:
space:
mode:
authorAkshesh <aksheshdoshi@gmail.com>2016-07-08 19:41:19 +0530
committerTim Graham <timograham@gmail.com>2016-08-11 14:36:31 -0400
commit324c1b432a2fa07c8f911f8b923ed04be32c52c7 (patch)
tree7f83fedd624f56ad1ade3b128ce6667f070bc665 /tests/indexes
parent7aeb7390fc4231119494a9ebdee3c6ee0d5af053 (diff)
Fixed #24442 -- Improved SchemaEditor's index name truncation.
Diffstat (limited to 'tests/indexes')
-rw-r--r--tests/indexes/tests.py30
1 files changed, 27 insertions, 3 deletions
diff --git a/tests/indexes/tests.py b/tests/indexes/tests.py
index 4bd2332674..3ef6d2939b 100644
--- a/tests/indexes/tests.py
+++ b/tests/indexes/tests.py
@@ -18,10 +18,34 @@ class SchemaIndexesTests(TestCase):
with connection.schema_editor() as editor:
index_name = editor._create_index_name(
model=Article,
- column_names=("c1", "c2", "c3"),
+ column_names=("c1",),
suffix="123",
)
- self.assertEqual(index_name, "indexes_article_c1_7ce4cc86123")
+ self.assertEqual(index_name, "indexes_article_c1_a52bd80b123")
+
+ def test_index_name(self):
+ """
+ Index names on the built-in database backends::
+ * Are truncated as needed.
+ * Include all the column names.
+ * Include a deterministic hash.
+ """
+ long_name = 'l%sng' % ('o' * 100)
+ with connection.schema_editor() as editor:
+ index_name = editor._create_index_name(
+ model=Article,
+ column_names=('c1', 'c2', long_name),
+ suffix='ix',
+ )
+ expected = {
+ 'mysql': 'indexes_article_c1_c2_looooooooooooooooooo_255179b2ix',
+ 'oracle': 'indexes_a_c1_c2_loo_255179b2ix',
+ 'postgresql': 'indexes_article_c1_c2_loooooooooooooooooo_255179b2ix',
+ 'sqlite': 'indexes_article_c1_c2_l%sng_255179b2ix' % ('o' * 100),
+ }
+ if connection.vendor not in expected:
+ self.skipTest('This test is only supported on the built-in database backends.')
+ self.assertEqual(index_name, expected[connection.vendor])
def test_index_together(self):
editor = connection.schema_editor()
@@ -71,6 +95,6 @@ class SchemaIndexesTests(TestCase):
self.skip("This test only applies to the InnoDB storage engine")
index_sql = connection.schema_editor()._model_indexes_sql(ArticleTranslation)
self.assertEqual(index_sql, [
- 'CREATE INDEX `indexes_articletranslation_99fb53c2` '
+ 'CREATE INDEX `indexes_articletranslation_article_no_constraint_id_d6c0806b` '
'ON `indexes_articletranslation` (`article_no_constraint_id`)'
])