summaryrefslogtreecommitdiff
path: root/tests/migrations/test_base.py
diff options
context:
space:
mode:
authorMichael Manfre <mmanfre@gmail.com>2014-01-09 10:05:15 -0500
committerMichael Manfre <mmanfre@gmail.com>2014-02-02 12:47:21 -0500
commit3ffeb931869cc68a8e0916219702ee282afc6e9d (patch)
treef24020307dd5b529989329bfabfc95effcecffe8 /tests/migrations/test_base.py
parent0837eacc4e1fa7916e48135e8ba43f54a7a64997 (diff)
Ensure cursors are closed when no longer needed.
This commit touchs various parts of the code base and test framework. Any found usage of opening a cursor for the sake of initializing a connection has been replaced with 'ensure_connection()'.
Diffstat (limited to 'tests/migrations/test_base.py')
-rw-r--r--tests/migrations/test_base.py35
1 files changed, 21 insertions, 14 deletions
diff --git a/tests/migrations/test_base.py b/tests/migrations/test_base.py
index 7ab09b04a5..2dba30b2aa 100644
--- a/tests/migrations/test_base.py
+++ b/tests/migrations/test_base.py
@@ -9,33 +9,40 @@ class MigrationTestBase(TransactionTestCase):
available_apps = ["migrations"]
+ def get_table_description(self, table):
+ with connection.cursor() as cursor:
+ return connection.introspection.get_table_description(cursor, table)
+
def assertTableExists(self, table):
- self.assertIn(table, connection.introspection.get_table_list(connection.cursor()))
+ with connection.cursor() as cursor:
+ self.assertIn(table, connection.introspection.get_table_list(cursor))
def assertTableNotExists(self, table):
- self.assertNotIn(table, connection.introspection.get_table_list(connection.cursor()))
+ with connection.cursor() as cursor:
+ self.assertNotIn(table, connection.introspection.get_table_list(cursor))
def assertColumnExists(self, table, column):
- self.assertIn(column, [c.name for c in connection.introspection.get_table_description(connection.cursor(), table)])
+ self.assertIn(column, [c.name for c in self.get_table_description(table)])
def assertColumnNotExists(self, table, column):
- self.assertNotIn(column, [c.name for c in connection.introspection.get_table_description(connection.cursor(), table)])
+ self.assertNotIn(column, [c.name for c in self.get_table_description(table)])
def assertColumnNull(self, table, column):
- self.assertEqual([c.null_ok for c in connection.introspection.get_table_description(connection.cursor(), table) if c.name == column][0], True)
+ self.assertEqual([c.null_ok for c in self.get_table_description(table) if c.name == column][0], True)
def assertColumnNotNull(self, table, column):
- self.assertEqual([c.null_ok for c in connection.introspection.get_table_description(connection.cursor(), table) if c.name == column][0], False)
+ self.assertEqual([c.null_ok for c in self.get_table_description(table) if c.name == column][0], False)
def assertIndexExists(self, table, columns, value=True):
- self.assertEqual(
- value,
- any(
- c["index"]
- for c in connection.introspection.get_constraints(connection.cursor(), table).values()
- if c['columns'] == list(columns)
- ),
- )
+ with connection.cursor() as cursor:
+ self.assertEqual(
+ value,
+ any(
+ c["index"]
+ for c in connection.introspection.get_constraints(cursor, table).values()
+ if c['columns'] == list(columns)
+ ),
+ )
def assertIndexNotExists(self, table, columns):
return self.assertIndexExists(table, columns, False)