summaryrefslogtreecommitdiff
path: root/tests/postgres_tests/test_indexes.py
diff options
context:
space:
mode:
authorNick Pope <nick.pope@flightdataservices.com>2017-12-05 09:15:22 +0000
committerTim Graham <timograham@gmail.com>2018-08-02 11:50:40 -0400
commitff9543b351e79de78e7867f255ad15e51555ba4a (patch)
tree16cf98eee21a5f6bb01201d133b7e38ffa64e690 /tests/postgres_tests/test_indexes.py
parent6b4d1ec8ff97cff4f1683912b0147d22410b05b8 (diff)
Refs #25809, #28990 -- Added PostgreSQL version check for BrinIndex support.
Diffstat (limited to 'tests/postgres_tests/test_indexes.py')
-rw-r--r--tests/postgres_tests/test_indexes.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/postgres_tests/test_indexes.py b/tests/postgres_tests/test_indexes.py
index 96ff829807..f4ac359a3a 100644
--- a/tests/postgres_tests/test_indexes.py
+++ b/tests/postgres_tests/test_indexes.py
@@ -1,7 +1,10 @@
+from unittest import mock
+
from django.contrib.postgres.indexes import (
BrinIndex, BTreeIndex, GinIndex, GistIndex, HashIndex, SpGistIndex,
)
from django.db import connection
+from django.db.utils import NotSupportedError
from django.test import skipUnlessDBFeature
from . import PostgreSQLTestCase
@@ -208,6 +211,25 @@ class SchemaTests(PostgreSQLTestCase):
editor.remove_index(CharFieldModel, index)
self.assertNotIn(index_name, self.get_constraints(CharFieldModel._meta.db_table))
+ def test_brin_index_not_supported(self):
+ index_name = 'brin_index_exception'
+ index = BrinIndex(fields=['field'], name=index_name)
+ with self.assertRaisesMessage(NotSupportedError, 'BRIN indexes require PostgreSQL 9.5+.'):
+ with mock.patch('django.db.connection.features.has_brin_index_support', False):
+ with connection.schema_editor() as editor:
+ editor.add_index(CharFieldModel, index)
+ self.assertNotIn(index_name, self.get_constraints(CharFieldModel._meta.db_table))
+
+ @skipUnlessDBFeature('has_brin_index_support')
+ def test_brin_autosummarize_not_supported(self):
+ index_name = 'brin_options_exception'
+ index = BrinIndex(fields=['field'], name=index_name, autosummarize=True)
+ with self.assertRaisesMessage(NotSupportedError, 'BRIN option autosummarize requires PostgreSQL 10+.'):
+ with mock.patch('django.db.connection.features.has_brin_autosummarize', False):
+ with connection.schema_editor() as editor:
+ editor.add_index(CharFieldModel, index)
+ self.assertNotIn(index_name, self.get_constraints(CharFieldModel._meta.db_table))
+
def test_btree_index(self):
# Ensure the table is there and doesn't have an index.
self.assertNotIn('field', self.get_constraints(CharFieldModel._meta.db_table))