summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2015-02-14 09:50:38 +0100
committerAymeric Augustin <aymeric.augustin@m4x.org>2015-02-14 18:52:28 +0100
commit87e9cad4a4481e7cd91e2e7bac46efe54000a932 (patch)
tree0b88166512e7ae426faea6516c68ee7ab9be4c68 /tests
parenta1fc97c1a7949b4e8a16d22ee33ca06c887af038 (diff)
[1.8.x] Fixed #24318 -- Set the transaction isolation level with psycopg >= 2.4.2.
Backport of 76356d96 from master
Diffstat (limited to 'tests')
-rw-r--r--tests/backends/tests.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/backends/tests.py b/tests/backends/tests.py
index 1ffe790048..edc4783f0e 100644
--- a/tests/backends/tests.py
+++ b/tests/backends/tests.py
@@ -238,6 +238,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,))