summaryrefslogtreecommitdiff
path: root/tests/indexes
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2020-02-03 19:07:00 -0800
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-02-06 15:35:23 +0100
commit3259983f569151232d8e3b0c3d0de3a858c2b265 (patch)
tree4f1f19368fbb9d73ea5245d8fabe5e3097f51926 /tests/indexes
parentf48f671223a20b161ca819cf7d6298e43b8ba5fe (diff)
downloaddjango-3259983f569151232d8e3b0c3d0de3a858c2b265.tar.gz
Fixed #31233 -- Closed database connections and cursors after use.
Diffstat (limited to 'tests/indexes')
-rw-r--r--tests/indexes/tests.py42
1 files changed, 24 insertions, 18 deletions
diff --git a/tests/indexes/tests.py b/tests/indexes/tests.py
index 5ef2835f4e..274ee54a37 100644
--- a/tests/indexes/tests.py
+++ b/tests/indexes/tests.py
@@ -270,9 +270,10 @@ class SchemaIndexesMySQLTests(TransactionTestCase):
MySQL on InnoDB already creates indexes automatically for foreign keys.
(#14180). An index should be created if db_constraint=False (#26171).
"""
- storage = connection.introspection.get_storage_engine(
- connection.cursor(), ArticleTranslation._meta.db_table
- )
+ with connection.cursor() as cursor:
+ storage = connection.introspection.get_storage_engine(
+ cursor, ArticleTranslation._meta.db_table,
+ )
if storage != "InnoDB":
self.skip("This test only applies to the InnoDB storage engine")
index_sql = [str(statement) for statement in connection.schema_editor()._model_indexes_sql(ArticleTranslation)]
@@ -326,9 +327,10 @@ class PartialIndexTests(TransactionTestCase):
str(index.create_sql(Article, schema_editor=editor))
)
editor.add_index(index=index, model=Article)
- self.assertIn(index.name, connection.introspection.get_constraints(
- cursor=connection.cursor(), table_name=Article._meta.db_table,
- ))
+ with connection.cursor() as cursor:
+ self.assertIn(index.name, connection.introspection.get_constraints(
+ cursor=cursor, table_name=Article._meta.db_table,
+ ))
editor.remove_index(index=index, model=Article)
def test_integer_restriction_partial(self):
@@ -343,9 +345,10 @@ class PartialIndexTests(TransactionTestCase):
str(index.create_sql(Article, schema_editor=editor))
)
editor.add_index(index=index, model=Article)
- self.assertIn(index.name, connection.introspection.get_constraints(
- cursor=connection.cursor(), table_name=Article._meta.db_table,
- ))
+ with connection.cursor() as cursor:
+ self.assertIn(index.name, connection.introspection.get_constraints(
+ cursor=cursor, table_name=Article._meta.db_table,
+ ))
editor.remove_index(index=index, model=Article)
def test_boolean_restriction_partial(self):
@@ -360,9 +363,10 @@ class PartialIndexTests(TransactionTestCase):
str(index.create_sql(Article, schema_editor=editor))
)
editor.add_index(index=index, model=Article)
- self.assertIn(index.name, connection.introspection.get_constraints(
- cursor=connection.cursor(), table_name=Article._meta.db_table,
- ))
+ with connection.cursor() as cursor:
+ self.assertIn(index.name, connection.introspection.get_constraints(
+ cursor=cursor, table_name=Article._meta.db_table,
+ ))
editor.remove_index(index=index, model=Article)
@skipUnlessDBFeature('supports_functions_in_partial_indexes')
@@ -390,9 +394,10 @@ class PartialIndexTests(TransactionTestCase):
# check ONLY the occurrence of headline in the SQL.
self.assertGreater(sql.rfind('headline'), where)
editor.add_index(index=index, model=Article)
- self.assertIn(index.name, connection.introspection.get_constraints(
- cursor=connection.cursor(), table_name=Article._meta.db_table,
- ))
+ with connection.cursor() as cursor:
+ self.assertIn(index.name, connection.introspection.get_constraints(
+ cursor=cursor, table_name=Article._meta.db_table,
+ ))
editor.remove_index(index=index, model=Article)
def test_is_null_condition(self):
@@ -407,7 +412,8 @@ class PartialIndexTests(TransactionTestCase):
str(index.create_sql(Article, schema_editor=editor))
)
editor.add_index(index=index, model=Article)
- self.assertIn(index.name, connection.introspection.get_constraints(
- cursor=connection.cursor(), table_name=Article._meta.db_table,
- ))
+ with connection.cursor() as cursor:
+ self.assertIn(index.name, connection.introspection.get_constraints(
+ cursor=cursor, table_name=Article._meta.db_table,
+ ))
editor.remove_index(index=index, model=Article)