diff options
Diffstat (limited to 'tests/backends/postgresql')
| -rw-r--r-- | tests/backends/postgresql/test_introspection.py | 24 | ||||
| -rw-r--r-- | tests/backends/postgresql/tests.py | 14 |
2 files changed, 19 insertions, 19 deletions
diff --git a/tests/backends/postgresql/test_introspection.py b/tests/backends/postgresql/test_introspection.py index cfa801a77f..4dcadbd733 100644 --- a/tests/backends/postgresql/test_introspection.py +++ b/tests/backends/postgresql/test_introspection.py @@ -9,15 +9,15 @@ from ..models import Person @unittest.skipUnless(connection.vendor == 'postgresql', "Test only for PostgreSQL") class DatabaseSequenceTests(TestCase): def test_get_sequences(self): - cursor = connection.cursor() - seqs = connection.introspection.get_sequences(cursor, Person._meta.db_table) - self.assertEqual( - seqs, - [{'table': Person._meta.db_table, 'column': 'id', 'name': 'backends_person_id_seq'}] - ) - cursor.execute('ALTER SEQUENCE backends_person_id_seq RENAME TO pers_seq') - seqs = connection.introspection.get_sequences(cursor, Person._meta.db_table) - self.assertEqual( - seqs, - [{'table': Person._meta.db_table, 'column': 'id', 'name': 'pers_seq'}] - ) + with connection.cursor() as cursor: + seqs = connection.introspection.get_sequences(cursor, Person._meta.db_table) + self.assertEqual( + seqs, + [{'table': Person._meta.db_table, 'column': 'id', 'name': 'backends_person_id_seq'}] + ) + cursor.execute('ALTER SEQUENCE backends_person_id_seq RENAME TO pers_seq') + seqs = connection.introspection.get_sequences(cursor, Person._meta.db_table) + self.assertEqual( + seqs, + [{'table': Person._meta.db_table, 'column': 'id', 'name': 'pers_seq'}] + ) diff --git a/tests/backends/postgresql/tests.py b/tests/backends/postgresql/tests.py index 140fbbc444..caa8b87fb9 100644 --- a/tests/backends/postgresql/tests.py +++ b/tests/backends/postgresql/tests.py @@ -44,10 +44,10 @@ class Tests(TestCase): # Ensure the database default time zone is different than # the time zone in new_connection.settings_dict. We can # get the default time zone by reset & show. - cursor = new_connection.cursor() - cursor.execute("RESET TIMEZONE") - cursor.execute("SHOW TIMEZONE") - db_default_tz = cursor.fetchone()[0] + with new_connection.cursor() as cursor: + cursor.execute("RESET TIMEZONE") + cursor.execute("SHOW TIMEZONE") + db_default_tz = cursor.fetchone()[0] new_tz = 'Europe/Paris' if db_default_tz == 'UTC' else 'UTC' new_connection.close() @@ -59,12 +59,12 @@ class Tests(TestCase): # time zone, run a query and rollback. with self.settings(TIME_ZONE=new_tz): new_connection.set_autocommit(False) - cursor = new_connection.cursor() new_connection.rollback() # Now let's see if the rollback rolled back the SET TIME ZONE. - cursor.execute("SHOW TIMEZONE") - tz = cursor.fetchone()[0] + with new_connection.cursor() as cursor: + cursor.execute("SHOW TIMEZONE") + tz = cursor.fetchone()[0] self.assertEqual(new_tz, tz) finally: |
