1
from unittest import skipUnless
1
3
from django.core.management.color import no_style
2
from django.db import connection, connections, DEFAULT_DB_ALIAS
4
from django.db import connection
3
5
from django.test import TestCase
4
from django.utils.unittest import skipUnless
6
from .models import Article
7
from .models import Article, IndexTogetherSingleList
9
10
class IndexesTests(TestCase):
10
11
def test_index_together(self):
11
connection = connections[DEFAULT_DB_ALIAS]
12
12
index_sql = connection.creation.sql_indexes_for_model(Article, no_style())
13
13
self.assertEqual(len(index_sql), 1)
15
@skipUnless(connections[DEFAULT_DB_ALIAS].vendor == 'postgresql',
15
def test_index_together_single_list(self):
16
# Test for using index_together with a single list (#22172)
17
index_sql = connection.creation.sql_indexes_for_model(IndexTogetherSingleList, no_style())
18
self.assertEqual(len(index_sql), 1)
20
@skipUnless(connection.vendor == 'postgresql',
16
21
"This is a postgresql-specific issue")
17
22
def test_postgresql_text_indexes(self):
18
23
"""Test creation of PostgreSQL-specific text indexes (#12234)"""
19
24
from .models import IndexedArticle
20
connection = connections[DEFAULT_DB_ALIAS]
21
25
index_sql = connection.creation.sql_indexes_for_model(IndexedArticle, no_style())
22
26
self.assertEqual(len(index_sql), 5)
23
27
self.assertIn('("headline" varchar_pattern_ops)', index_sql[1])