Refs #28478 -- Prevented connection creation in model_indexes tests.
Entering a SchemaEditor instance creates a connection but it isn't needed for this test.
This commit is contained in:
parent
573f44d62f
commit
a02a6fd580
|
@ -158,36 +158,36 @@ class IndexesTests(SimpleTestCase):
|
||||||
|
|
||||||
@skipUnlessDBFeature('supports_tablespaces')
|
@skipUnlessDBFeature('supports_tablespaces')
|
||||||
def test_db_tablespace(self):
|
def test_db_tablespace(self):
|
||||||
with connection.schema_editor() as editor:
|
editor = connection.schema_editor()
|
||||||
# Index with db_tablespace attribute.
|
# Index with db_tablespace attribute.
|
||||||
for fields in [
|
for fields in [
|
||||||
# Field with db_tablespace specified on model.
|
# Field with db_tablespace specified on model.
|
||||||
['shortcut'],
|
['shortcut'],
|
||||||
# Field without db_tablespace specified on model.
|
# Field without db_tablespace specified on model.
|
||||||
['author'],
|
['author'],
|
||||||
# Multi-column with db_tablespaces specified on model.
|
# Multi-column with db_tablespaces specified on model.
|
||||||
['shortcut', 'isbn'],
|
['shortcut', 'isbn'],
|
||||||
# Multi-column without db_tablespace specified on model.
|
# Multi-column without db_tablespace specified on model.
|
||||||
['title', 'author'],
|
['title', 'author'],
|
||||||
]:
|
]:
|
||||||
with self.subTest(fields=fields):
|
with self.subTest(fields=fields):
|
||||||
index = models.Index(fields=fields, db_tablespace='idx_tbls2')
|
index = models.Index(fields=fields, db_tablespace='idx_tbls2')
|
||||||
self.assertIn('"idx_tbls2"', str(index.create_sql(Book, editor)).lower())
|
self.assertIn('"idx_tbls2"', str(index.create_sql(Book, editor)).lower())
|
||||||
# Indexes without db_tablespace attribute.
|
# Indexes without db_tablespace attribute.
|
||||||
for fields in [['author'], ['shortcut', 'isbn'], ['title', 'author']]:
|
for fields in [['author'], ['shortcut', 'isbn'], ['title', 'author']]:
|
||||||
with self.subTest(fields=fields):
|
with self.subTest(fields=fields):
|
||||||
index = models.Index(fields=fields)
|
index = models.Index(fields=fields)
|
||||||
# The DEFAULT_INDEX_TABLESPACE setting can't be tested
|
# The DEFAULT_INDEX_TABLESPACE setting can't be tested because
|
||||||
# because it's evaluated when the model class is defined.
|
# it's evaluated when the model class is defined. As a
|
||||||
# As a consequence, @override_settings doesn't work.
|
# consequence, @override_settings doesn't work.
|
||||||
if settings.DEFAULT_INDEX_TABLESPACE:
|
if settings.DEFAULT_INDEX_TABLESPACE:
|
||||||
self.assertIn(
|
self.assertIn(
|
||||||
'"%s"' % settings.DEFAULT_INDEX_TABLESPACE,
|
'"%s"' % settings.DEFAULT_INDEX_TABLESPACE,
|
||||||
str(index.create_sql(Book, editor)).lower()
|
str(index.create_sql(Book, editor)).lower()
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
self.assertNotIn('TABLESPACE', str(index.create_sql(Book, editor)))
|
self.assertNotIn('TABLESPACE', str(index.create_sql(Book, editor)))
|
||||||
# Field with db_tablespace specified on the model and an index
|
# Field with db_tablespace specified on the model and an index without
|
||||||
# without db_tablespace.
|
# db_tablespace.
|
||||||
index = models.Index(fields=['shortcut'])
|
index = models.Index(fields=['shortcut'])
|
||||||
self.assertIn('"idx_tbls"', str(index.create_sql(Book, editor)).lower())
|
self.assertIn('"idx_tbls"', str(index.create_sql(Book, editor)).lower())
|
||||||
|
|
Loading…
Reference in New Issue