summaryrefslogtreecommitdiff
path: root/tests/postgres_tests/test_indexes.py
diff options
context:
space:
mode:
authorHannes Ljungberg <hannes@5monkeys.se>2019-10-31 13:33:53 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-06-04 12:26:22 +0200
commit8c7992f658e1125f8dc20b19206e8bbbe4187372 (patch)
treeba09524a9a3d27bb33f22dc92dec4b60a80f37e1 /tests/postgres_tests/test_indexes.py
parentf997b5e6ae85e2df2342b1a7812fe8130206c957 (diff)
Fixed #30913 -- Added support for covering indexes on PostgreSQL 11+.
Diffstat (limited to 'tests/postgres_tests/test_indexes.py')
-rw-r--r--tests/postgres_tests/test_indexes.py29
1 files changed, 28 insertions, 1 deletions
diff --git a/tests/postgres_tests/test_indexes.py b/tests/postgres_tests/test_indexes.py
index 0440beda5d..b9888f4843 100644
--- a/tests/postgres_tests/test_indexes.py
+++ b/tests/postgres_tests/test_indexes.py
@@ -11,7 +11,7 @@ from django.test import skipUnlessDBFeature
from django.test.utils import register_lookup
from . import PostgreSQLSimpleTestCase, PostgreSQLTestCase
-from .models import CharFieldModel, IntegerArrayModel
+from .models import CharFieldModel, IntegerArrayModel, Scene
class IndexTestMixin:
@@ -373,6 +373,33 @@ class SchemaTests(PostgreSQLTestCase):
editor.remove_index(CharFieldModel, index)
self.assertNotIn(index_name, self.get_constraints(CharFieldModel._meta.db_table))
+ @skipUnlessDBFeature('supports_covering_gist_indexes')
+ def test_gist_include(self):
+ index_name = 'scene_gist_include_setting'
+ index = GistIndex(name=index_name, fields=['scene'], include=['setting'])
+ with connection.schema_editor() as editor:
+ editor.add_index(Scene, index)
+ constraints = self.get_constraints(Scene._meta.db_table)
+ self.assertIn(index_name, constraints)
+ self.assertEqual(constraints[index_name]['type'], GistIndex.suffix)
+ self.assertEqual(constraints[index_name]['columns'], ['scene', 'setting'])
+ with connection.schema_editor() as editor:
+ editor.remove_index(Scene, index)
+ self.assertNotIn(index_name, self.get_constraints(Scene._meta.db_table))
+
+ def test_gist_include_not_supported(self):
+ index_name = 'gist_include_exception'
+ index = GistIndex(fields=['scene'], name=index_name, include=['setting'])
+ msg = 'Covering GiST indexes requires PostgreSQL 12+.'
+ with self.assertRaisesMessage(NotSupportedError, msg):
+ with mock.patch(
+ 'django.db.backends.postgresql.features.DatabaseFeatures.supports_covering_gist_indexes',
+ False,
+ ):
+ with connection.schema_editor() as editor:
+ editor.add_index(Scene, index)
+ self.assertNotIn(index_name, self.get_constraints(Scene._meta.db_table))
+
def test_hash_index(self):
# Ensure the table is there and doesn't have an index.
self.assertNotIn('field', self.get_constraints(CharFieldModel._meta.db_table))