diff options
| author | Nick Pope <nick@nickpope.me.uk> | 2021-05-28 23:52:57 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-10-01 13:11:34 +0200 |
| commit | e76f9d5b443845639262e18d9020ef4b070f1c7d (patch) | |
| tree | 1119213b5e3143318040026770efc649c1fd260d /tests/postgres_tests/test_indexes.py | |
| parent | bd47b9bc816bf213b6d0027ed9a9a44955bb7694 (diff) | |
Refs #32943 -- Added support for covering SP-GiST indexes on PostgreSQL 14+.
Diffstat (limited to 'tests/postgres_tests/test_indexes.py')
| -rw-r--r-- | tests/postgres_tests/test_indexes.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/postgres_tests/test_indexes.py b/tests/postgres_tests/test_indexes.py index e5d1bb02bb..75d0640a08 100644 --- a/tests/postgres_tests/test_indexes.py +++ b/tests/postgres_tests/test_indexes.py @@ -518,6 +518,33 @@ class SchemaTests(PostgreSQLTestCase): editor.remove_index(TextFieldModel, index) self.assertNotIn(index_name, self.get_constraints(TextFieldModel._meta.db_table)) + @skipUnlessDBFeature('supports_covering_spgist_indexes') + def test_spgist_include(self): + index_name = 'scene_spgist_include_setting' + index = SpGistIndex(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'], SpGistIndex.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_spgist_include_not_supported(self): + index_name = 'spgist_include_exception' + index = SpGistIndex(fields=['scene'], name=index_name, include=['setting']) + msg = 'Covering SP-GiST indexes require PostgreSQL 14+.' + with self.assertRaisesMessage(NotSupportedError, msg): + with mock.patch( + 'django.db.backends.postgresql.features.DatabaseFeatures.supports_covering_spgist_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_op_class(self): index_name = 'test_op_class' index = Index( |
