diff options
| author | Nick Pope <nick.pope@flightdataservices.com> | 2018-07-30 23:28:11 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2018-08-02 11:42:57 -0400 |
| commit | 6b4d1ec8ff97cff4f1683912b0147d22410b05b8 (patch) | |
| tree | 07604a2c67f6378cc96084445ecd90fe8a0a23ea /tests/postgres_tests | |
| parent | d6381d3559b469ce25f4906151b9329c1f946f14 (diff) | |
Fixed #29614 -- Added BTreeIndex to django.contrib.postres.
Diffstat (limited to 'tests/postgres_tests')
| -rw-r--r-- | tests/postgres_tests/test_indexes.py | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/tests/postgres_tests/test_indexes.py b/tests/postgres_tests/test_indexes.py index 9bca4510fe..96ff829807 100644 --- a/tests/postgres_tests/test_indexes.py +++ b/tests/postgres_tests/test_indexes.py @@ -1,5 +1,5 @@ from django.contrib.postgres.indexes import ( - BrinIndex, GinIndex, GistIndex, HashIndex, SpGistIndex, + BrinIndex, BTreeIndex, GinIndex, GistIndex, HashIndex, SpGistIndex, ) from django.db import connection from django.test import skipUnlessDBFeature @@ -47,6 +47,20 @@ class BrinIndexTests(IndexTestMixin, PostgreSQLTestCase): BrinIndex(fields=['title'], name='test_title_brin', pages_per_range=0) +class BTreeIndexTests(IndexTestMixin, PostgreSQLTestCase): + index_class = BTreeIndex + + def test_suffix(self): + self.assertEqual(BTreeIndex.suffix, 'btree') + + def test_deconstruction(self): + index = BTreeIndex(fields=['title'], name='test_title_btree', fillfactor=80) + path, args, kwargs = index.deconstruct() + self.assertEqual(path, 'django.contrib.postgres.indexes.BTreeIndex') + self.assertEqual(args, ()) + self.assertEqual(kwargs, {'fields': ['title'], 'name': 'test_title_btree', 'fillfactor': 80}) + + class GinIndexTests(IndexTestMixin, PostgreSQLTestCase): index_class = GinIndex @@ -194,6 +208,34 @@ class SchemaTests(PostgreSQLTestCase): editor.remove_index(CharFieldModel, index) self.assertNotIn(index_name, self.get_constraints(CharFieldModel._meta.db_table)) + def test_btree_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_btree' + index = BTreeIndex(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'], BTreeIndex.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)) + + def test_btree_parameters(self): + index_name = 'integer_array_btree_fillfactor' + index = BTreeIndex(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'], BTreeIndex.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)) + def test_gist_index(self): # Ensure the table is there and doesn't have an index. self.assertNotIn('field', self.get_constraints(CharFieldModel._meta.db_table)) |
