コード例 #1
0
 def test_deconstruction(self):
     index = SpGistIndex(fields=["title"], name="test_title_spgist", fillfactor=80)
     path, args, kwargs = index.deconstruct()
     self.assertEqual(path, "django.contrib.postgres.indexes.SpGistIndex")
     self.assertEqual(args, ())
     self.assertEqual(
         kwargs, {"fields": ["title"], "name": "test_title_spgist", "fillfactor": 80}
     )
コード例 #2
0
ファイル: test_indexes.py プロジェクト: betterlif/djangopro
 def test_deconstruction(self):
     index = SpGistIndex(fields=['title'],
                         name='test_title_spgist',
                         fillfactor=80)
     path, args, kwargs = index.deconstruct()
     self.assertEqual(path, 'django.contrib.postgres.indexes.SpGistIndex')
     self.assertEqual(args, ())
     self.assertEqual(kwargs, {
         'fields': ['title'],
         'name': 'test_title_spgist',
         'fillfactor': 80
     })
コード例 #3
0
 def test_spgist_parameters(self):
     index_name = 'integer_array_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)
     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))
コード例 #4
0
 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))
コード例 #5
0
 def test_spgist_parameters(self):
     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(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(TextFieldModel, index)
     self.assertNotIn(index_name,
                      self.get_constraints(TextFieldModel._meta.db_table))
コード例 #6
0
 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))
コード例 #7
0
 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))
     # Add the index.
     index_name = 'char_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)
     # 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))
コード例 #8
0
ファイル: test_indexes.py プロジェクト: funkybob/django
 def test_deconstruction(self):
     index = SpGistIndex(fields=['title'], name='test_title_spgist', fillfactor=80)
     path, args, kwargs = index.deconstruct()
     self.assertEqual(path, 'django.contrib.postgres.indexes.SpGistIndex')
     self.assertEqual(args, ())
     self.assertEqual(kwargs, {'fields': ['title'], 'name': 'test_title_spgist', 'fillfactor': 80})