Fixed SpGistIndex tests on PostgreSQL 14+.

This commit is contained in:
Nick Pope 2021-10-01 08:33:27 +02:00 committed by Mariusz Felisiak
parent 98c8bf1cee
commit dd26362f63
1 changed files with 11 additions and 11 deletions

View File

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