diff options
Diffstat (limited to 'tests/postgres_tests')
| -rw-r--r-- | tests/postgres_tests/migrations/0002_create_test_models.py | 2 | ||||
| -rw-r--r-- | tests/postgres_tests/models.py | 2 | ||||
| -rw-r--r-- | tests/postgres_tests/test_indexes.py | 27 |
3 files changed, 29 insertions, 2 deletions
diff --git a/tests/postgres_tests/migrations/0002_create_test_models.py b/tests/postgres_tests/migrations/0002_create_test_models.py index 32f99ed6bb..377e220db1 100644 --- a/tests/postgres_tests/migrations/0002_create_test_models.py +++ b/tests/postgres_tests/migrations/0002_create_test_models.py @@ -142,7 +142,7 @@ class Migration(migrations.Migration): name='Scene', fields=[ ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), - ('scene', models.CharField(max_length=255)), + ('scene', models.TextField()), ('setting', models.CharField(max_length=255)), ], options=None, diff --git a/tests/postgres_tests/models.py b/tests/postgres_tests/models.py index fa20378071..adb2e89201 100644 --- a/tests/postgres_tests/models.py +++ b/tests/postgres_tests/models.py @@ -101,7 +101,7 @@ class BigAutoFieldModel(models.Model): # Scene/Character/Line models are used to test full text search. They're # populated with content from Monty Python and the Holy Grail. class Scene(models.Model): - scene = models.CharField(max_length=255) + scene = models.TextField() setting = models.CharField(max_length=255) 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( |
