[4.0.x] Fixed SpGistIndex tests on PostgreSQL 14+.

Backport of dd26362f63 from main
This commit is contained in:
Nick Pope 2021-10-01 08:33:27 +02:00 committed by Mariusz Felisiak
parent 81bb0ae221
commit fbcd7df120
1 changed files with 11 additions and 11 deletions

View File

@ -492,31 +492,31 @@ class SchemaTests(PostgreSQLTestCase):
def test_spgist_index(self):
# Ensure the table is there and doesn't have an index.
self.assertNotIn('field', self.get_constraints(CharFieldModel._meta.db_table))
self.assertNotIn('field', self.get_constraints(TextFieldModel._meta.db_table))
# Add the index.
index_name = 'char_field_model_field_spgist'
index_name = 'text_field_model_field_spgist'
index = SpGistIndex(fields=['field'], name=index_name)
with connection.schema_editor() as editor:
editor.add_index(CharFieldModel, index)
constraints = self.get_constraints(CharFieldModel._meta.db_table)
editor.add_index(TextFieldModel, index)
constraints = self.get_constraints(TextFieldModel._meta.db_table)
# The index was added.
self.assertEqual(constraints[index_name]['type'], SpGistIndex.suffix)
# Drop the index.
with connection.schema_editor() as editor:
editor.remove_index(CharFieldModel, index)
self.assertNotIn(index_name, self.get_constraints(CharFieldModel._meta.db_table))
editor.remove_index(TextFieldModel, index)
self.assertNotIn(index_name, self.get_constraints(TextFieldModel._meta.db_table))
def test_spgist_parameters(self):
index_name = 'integer_array_spgist_fillfactor'
index_name = 'text_field_model_spgist_fillfactor'
index = SpGistIndex(fields=['field'], name=index_name, fillfactor=80)
with connection.schema_editor() as editor:
editor.add_index(CharFieldModel, index)
constraints = self.get_constraints(CharFieldModel._meta.db_table)
editor.add_index(TextFieldModel, index)
constraints = self.get_constraints(TextFieldModel._meta.db_table)
self.assertEqual(constraints[index_name]['type'], SpGistIndex.suffix)
self.assertEqual(constraints[index_name]['options'], ['fillfactor=80'])
with connection.schema_editor() as editor:
editor.remove_index(CharFieldModel, index)
self.assertNotIn(index_name, self.get_constraints(CharFieldModel._meta.db_table))
editor.remove_index(TextFieldModel, index)
self.assertNotIn(index_name, self.get_constraints(TextFieldModel._meta.db_table))
def test_op_class(self):
index_name = 'test_op_class'