diff options
| author | Simon Charette <charette.s@gmail.com> | 2019-01-12 14:26:24 -0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2019-01-13 13:47:08 -0500 |
| commit | a02a6fd5805f9f0e613b9951249555876b8c4041 (patch) | |
| tree | 4583955946ed06d82f01ede0056a369590e53e60 | |
| parent | 573f44d62fe1e87e2c20a74eba5e20ca9ff0ed85 (diff) | |
Refs #28478 -- Prevented connection creation in model_indexes tests.
Entering a SchemaEditor instance creates a connection but it isn't needed
for this test.
| -rw-r--r-- | tests/model_indexes/tests.py | 66 |
1 files changed, 33 insertions, 33 deletions
diff --git a/tests/model_indexes/tests.py b/tests/model_indexes/tests.py index 71825043f8..0a34584c3e 100644 --- a/tests/model_indexes/tests.py +++ b/tests/model_indexes/tests.py @@ -158,36 +158,36 @@ class IndexesTests(SimpleTestCase): @skipUnlessDBFeature('supports_tablespaces') def test_db_tablespace(self): - with connection.schema_editor() as editor: - # Index with db_tablespace attribute. - for fields in [ - # Field with db_tablespace specified on model. - ['shortcut'], - # Field without db_tablespace specified on model. - ['author'], - # Multi-column with db_tablespaces specified on model. - ['shortcut', 'isbn'], - # Multi-column without db_tablespace specified on model. - ['title', 'author'], - ]: - with self.subTest(fields=fields): - index = models.Index(fields=fields, db_tablespace='idx_tbls2') - self.assertIn('"idx_tbls2"', str(index.create_sql(Book, editor)).lower()) - # Indexes without db_tablespace attribute. - for fields in [['author'], ['shortcut', 'isbn'], ['title', 'author']]: - with self.subTest(fields=fields): - index = models.Index(fields=fields) - # The DEFAULT_INDEX_TABLESPACE setting can't be tested - # because it's evaluated when the model class is defined. - # As a consequence, @override_settings doesn't work. - if settings.DEFAULT_INDEX_TABLESPACE: - self.assertIn( - '"%s"' % settings.DEFAULT_INDEX_TABLESPACE, - str(index.create_sql(Book, editor)).lower() - ) - else: - self.assertNotIn('TABLESPACE', str(index.create_sql(Book, editor))) - # Field with db_tablespace specified on the model and an index - # without db_tablespace. - index = models.Index(fields=['shortcut']) - self.assertIn('"idx_tbls"', str(index.create_sql(Book, editor)).lower()) + editor = connection.schema_editor() + # Index with db_tablespace attribute. + for fields in [ + # Field with db_tablespace specified on model. + ['shortcut'], + # Field without db_tablespace specified on model. + ['author'], + # Multi-column with db_tablespaces specified on model. + ['shortcut', 'isbn'], + # Multi-column without db_tablespace specified on model. + ['title', 'author'], + ]: + with self.subTest(fields=fields): + index = models.Index(fields=fields, db_tablespace='idx_tbls2') + self.assertIn('"idx_tbls2"', str(index.create_sql(Book, editor)).lower()) + # Indexes without db_tablespace attribute. + for fields in [['author'], ['shortcut', 'isbn'], ['title', 'author']]: + with self.subTest(fields=fields): + index = models.Index(fields=fields) + # The DEFAULT_INDEX_TABLESPACE setting can't be tested because + # it's evaluated when the model class is defined. As a + # consequence, @override_settings doesn't work. + if settings.DEFAULT_INDEX_TABLESPACE: + self.assertIn( + '"%s"' % settings.DEFAULT_INDEX_TABLESPACE, + str(index.create_sql(Book, editor)).lower() + ) + else: + self.assertNotIn('TABLESPACE', str(index.create_sql(Book, editor))) + # Field with db_tablespace specified on the model and an index without + # db_tablespace. + index = models.Index(fields=['shortcut']) + self.assertIn('"idx_tbls"', str(index.create_sql(Book, editor)).lower()) |
