1
from django.core.management.color import no_style
2
from django.db import connections, DEFAULT_DB_ALIAS
3
from django.test import TestCase
4
from django.utils.unittest import skipUnless
6
from .models import Article
9
class IndexesTests(TestCase):
10
def test_index_together(self):
11
connection = connections[DEFAULT_DB_ALIAS]
12
index_sql = connection.creation.sql_indexes_for_model(Article, no_style())
13
self.assertEqual(len(index_sql), 1)
15
@skipUnless(connections[DEFAULT_DB_ALIAS].vendor == 'postgresql',
16
"This is a postgresql-specific issue")
17
def test_postgresql_text_indexes(self):
18
"""Test creation of PostgreSQL-specific text indexes (#12234)"""
19
from .models import IndexedArticle
20
connection = connections[DEFAULT_DB_ALIAS]
21
index_sql = connection.creation.sql_indexes_for_model(IndexedArticle, no_style())
22
self.assertEqual(len(index_sql), 5)
23
self.assertIn('("headline" varchar_pattern_ops)', index_sql[1])
24
self.assertIn('("body" text_pattern_ops)', index_sql[3])
25
# unique=True and db_index=True should only create the varchar-specific
27
self.assertIn('("slug" varchar_pattern_ops)', index_sql[4])