diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2015-02-14 09:50:38 +0100 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2015-02-14 18:51:11 +0100 |
| commit | 76356d963c131252e1ce4285083fd21fd0bdedd9 (patch) | |
| tree | b34a5b2b5e2f83ca7d2257973b706a67178abb86 /tests | |
| parent | 1379165b3548b843980e59201eea8961a0b30a2d (diff) | |
Fixed #24318 -- Set the transaction isolation level with psycopg >= 2.4.2.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/backends/tests.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/backends/tests.py b/tests/backends/tests.py index 8762d263b9..52c6d44051 100644 --- a/tests/backends/tests.py +++ b/tests/backends/tests.py @@ -237,6 +237,34 @@ class PostgreSQLTests(TestCase): finally: new_connection.close() + def test_connect_isolation_level(self): + """ + Regression test for #18130 and #24318. + """ + from psycopg2.extensions import ( + ISOLATION_LEVEL_READ_COMMITTED as read_committed, + ISOLATION_LEVEL_SERIALIZABLE as serializable, + ) + + # Since this is a django.test.TestCase, a transaction is in progress + # and the isolation level isn't reported as 0. This test assumes that + # PostgreSQL is configured with the default isolation level. + + # Check the level on the psycopg2 connection, not the Django wrapper. + self.assertEqual(connection.connection.isolation_level, read_committed) + + databases = copy.deepcopy(settings.DATABASES) + databases[DEFAULT_DB_ALIAS]['OPTIONS']['isolation_level'] = serializable + new_connections = ConnectionHandler(databases) + new_connection = new_connections[DEFAULT_DB_ALIAS] + try: + # Start a transaction so the isolation level isn't reported as 0. + new_connection.set_autocommit(False) + # Check the level on the psycopg2 connection, not the Django wrapper. + self.assertEqual(new_connection.connection.isolation_level, serializable) + finally: + new_connection.close() + def _select(self, val): with connection.cursor() as cursor: cursor.execute("SELECT %s", (val,)) |
