summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
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 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,))