summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2012-12-18 09:56:30 +0100
committerClaude Paroz <claude@2xlibre.net>2012-12-18 10:04:47 +0100
commitddea0e0d7ee1a885f8ecbe45d7306a39c7780d63 (patch)
treef53c8e1b5d141a65b42f7a1f43cf0ea552f143e3 /tests
parent1caa483914edf851137b3c1e39f4364772bd46c9 (diff)
[1.5.x] Fixed #19441 -- Created PostgreSQL varchar index when unique=True
Thanks Dylan Verheul for the report and Anssi Kääriäinen for the review. Backport of 55972ee5c from master.
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/indexes/models.py6
-rw-r--r--tests/regressiontests/indexes/tests.py16
2 files changed, 21 insertions, 1 deletions
diff --git a/tests/regressiontests/indexes/models.py b/tests/regressiontests/indexes/models.py
index 9758377f99..47ba5896a8 100644
--- a/tests/regressiontests/indexes/models.py
+++ b/tests/regressiontests/indexes/models.py
@@ -9,3 +9,9 @@ class Article(models.Model):
index_together = [
["headline", "pub_date"],
]
+
+
+class IndexedArticle(models.Model):
+ headline = models.CharField(max_length=100, db_index=True)
+ body = models.TextField(db_index=True)
+ slug = models.CharField(max_length=40, unique=True, db_index=True)
diff --git a/tests/regressiontests/indexes/tests.py b/tests/regressiontests/indexes/tests.py
index 0dac881fa9..f3a32a44bb 100644
--- a/tests/regressiontests/indexes/tests.py
+++ b/tests/regressiontests/indexes/tests.py
@@ -1,8 +1,9 @@
from django.core.management.color import no_style
from django.db import connections, DEFAULT_DB_ALIAS
from django.test import TestCase
+from django.utils.unittest import skipUnless
-from .models import Article
+from .models import Article, IndexedArticle
class IndexesTests(TestCase):
@@ -10,3 +11,16 @@ class IndexesTests(TestCase):
connection = connections[DEFAULT_DB_ALIAS]
index_sql = connection.creation.sql_indexes_for_model(Article, no_style())
self.assertEqual(len(index_sql), 1)
+
+ @skipUnless(connections[DEFAULT_DB_ALIAS].vendor == 'postgresql',
+ "This is a postgresql-specific issue")
+ def test_postgresql_text_indexes(self):
+ """Test creation of PostgreSQL-specific text indexes (#12234)"""
+ connection = connections[DEFAULT_DB_ALIAS]
+ index_sql = connection.creation.sql_indexes_for_model(IndexedArticle, no_style())
+ self.assertEqual(len(index_sql), 5)
+ self.assertIn('("headline" varchar_pattern_ops)', index_sql[1])
+ self.assertIn('("body" text_pattern_ops)', index_sql[3])
+ # unique=True and db_index=True should only create the varchar-specific
+ # index (#19441).
+ self.assertIn('("slug" varchar_pattern_ops)', index_sql[4])