diff options
author | Florian Apolloner <florian@apolloner.eu> | 2022-12-12 09:40:08 +0100 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-12-12 10:36:42 +0100 |
commit | 1d90c9b1132482d446ca8375c151e894002c9e8d (patch) | |
tree | 3ce0bf7b9abea96d1b8669b0181f39c4f5a047af /tests/backends | |
parent | 2f38f7b8f9bd65905dc6bec4f3e2a30b5da8e338 (diff) | |
download | django-1d90c9b1132482d446ca8375c151e894002c9e8d.tar.gz |
Refs #33308 -- Added psycopg_any.IsolationLevel.
Diffstat (limited to 'tests/backends')
-rw-r--r-- | tests/backends/postgresql/tests.py | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/tests/backends/postgresql/tests.py b/tests/backends/postgresql/tests.py index d375bd2b8c..41d445e6c7 100644 --- a/tests/backends/postgresql/tests.py +++ b/tests/backends/postgresql/tests.py @@ -223,7 +223,7 @@ class Tests(TestCase): The transaction level can be configured with DATABASES ['OPTIONS']['isolation_level']. """ - from psycopg2.extensions import ISOLATION_LEVEL_SERIALIZABLE as serializable + from django.db.backends.postgresql.psycopg_any import IsolationLevel # 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 @@ -232,15 +232,31 @@ class Tests(TestCase): self.assertIsNone(connection.connection.isolation_level) new_connection = connection.copy() - new_connection.settings_dict["OPTIONS"]["isolation_level"] = serializable + new_connection.settings_dict["OPTIONS"][ + "isolation_level" + ] = IsolationLevel.SERIALIZABLE 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) + self.assertEqual( + new_connection.connection.isolation_level, + IsolationLevel.SERIALIZABLE, + ) finally: new_connection.close() + def test_connect_invalid_isolation_level(self): + self.assertIsNone(connection.connection.isolation_level) + new_connection = connection.copy() + new_connection.settings_dict["OPTIONS"]["isolation_level"] = -1 + msg = ( + "Invalid transaction isolation level -1 specified. Use one of the " + "IsolationLevel values." + ) + with self.assertRaisesMessage(ImproperlyConfigured, msg): + new_connection.ensure_connection() + def test_connect_no_is_usable_checks(self): new_connection = connection.copy() try: |