mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Refs #33476 -- Reformatted code with Black.
This commit is contained in:
committed by
Mariusz Felisiak
parent
f68fa8b45d
commit
9c19aff7c7
@@ -14,20 +14,21 @@ def get_connection():
|
||||
|
||||
|
||||
@override_settings(DEBUG=True)
|
||||
@unittest.skipUnless(connection.vendor == 'mysql', 'MySQL tests')
|
||||
@unittest.skipUnless(connection.vendor == "mysql", "MySQL tests")
|
||||
class IsolationLevelTests(TestCase):
|
||||
|
||||
read_committed = 'read committed'
|
||||
repeatable_read = 'repeatable read'
|
||||
read_committed = "read committed"
|
||||
repeatable_read = "repeatable read"
|
||||
isolation_values = {
|
||||
level: level.upper()
|
||||
for level in (read_committed, repeatable_read)
|
||||
level: level.upper() for level in (read_committed, repeatable_read)
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
configured_isolation_level = connection.isolation_level or cls.isolation_values[cls.repeatable_read]
|
||||
configured_isolation_level = (
|
||||
connection.isolation_level or cls.isolation_values[cls.repeatable_read]
|
||||
)
|
||||
cls.configured_isolation_level = configured_isolation_level.upper()
|
||||
cls.other_isolation_level = (
|
||||
cls.read_committed
|
||||
@@ -38,50 +39,58 @@ class IsolationLevelTests(TestCase):
|
||||
@staticmethod
|
||||
def get_isolation_level(connection):
|
||||
with connection.cursor() as cursor:
|
||||
cursor.execute("SHOW VARIABLES WHERE variable_name IN ('transaction_isolation', 'tx_isolation')")
|
||||
return cursor.fetchone()[1].replace('-', ' ')
|
||||
cursor.execute(
|
||||
"SHOW VARIABLES WHERE variable_name IN ('transaction_isolation', 'tx_isolation')"
|
||||
)
|
||||
return cursor.fetchone()[1].replace("-", " ")
|
||||
|
||||
def test_auto_is_null_auto_config(self):
|
||||
query = 'set sql_auto_is_null = 0'
|
||||
query = "set sql_auto_is_null = 0"
|
||||
connection.init_connection_state()
|
||||
last_query = connection.queries[-1]['sql'].lower()
|
||||
last_query = connection.queries[-1]["sql"].lower()
|
||||
if connection.features.is_sql_auto_is_null_enabled:
|
||||
self.assertIn(query, last_query)
|
||||
else:
|
||||
self.assertNotIn(query, last_query)
|
||||
|
||||
def test_connect_isolation_level(self):
|
||||
self.assertEqual(self.get_isolation_level(connection), self.configured_isolation_level)
|
||||
self.assertEqual(
|
||||
self.get_isolation_level(connection), self.configured_isolation_level
|
||||
)
|
||||
|
||||
def test_setting_isolation_level(self):
|
||||
with get_connection() as new_connection:
|
||||
new_connection.settings_dict['OPTIONS']['isolation_level'] = self.other_isolation_level
|
||||
new_connection.settings_dict["OPTIONS"][
|
||||
"isolation_level"
|
||||
] = self.other_isolation_level
|
||||
self.assertEqual(
|
||||
self.get_isolation_level(new_connection),
|
||||
self.isolation_values[self.other_isolation_level]
|
||||
self.isolation_values[self.other_isolation_level],
|
||||
)
|
||||
|
||||
def test_uppercase_isolation_level(self):
|
||||
# Upper case values are also accepted in 'isolation_level'.
|
||||
with get_connection() as new_connection:
|
||||
new_connection.settings_dict['OPTIONS']['isolation_level'] = self.other_isolation_level.upper()
|
||||
new_connection.settings_dict["OPTIONS"][
|
||||
"isolation_level"
|
||||
] = self.other_isolation_level.upper()
|
||||
self.assertEqual(
|
||||
self.get_isolation_level(new_connection),
|
||||
self.isolation_values[self.other_isolation_level]
|
||||
self.isolation_values[self.other_isolation_level],
|
||||
)
|
||||
|
||||
def test_default_isolation_level(self):
|
||||
# If not specified in settings, the default is read committed.
|
||||
with get_connection() as new_connection:
|
||||
new_connection.settings_dict['OPTIONS'].pop('isolation_level', None)
|
||||
new_connection.settings_dict["OPTIONS"].pop("isolation_level", None)
|
||||
self.assertEqual(
|
||||
self.get_isolation_level(new_connection),
|
||||
self.isolation_values[self.read_committed]
|
||||
self.isolation_values[self.read_committed],
|
||||
)
|
||||
|
||||
def test_isolation_level_validation(self):
|
||||
new_connection = connection.copy()
|
||||
new_connection.settings_dict['OPTIONS']['isolation_level'] = 'xxx'
|
||||
new_connection.settings_dict["OPTIONS"]["isolation_level"] = "xxx"
|
||||
msg = (
|
||||
"Invalid transaction isolation level 'xxx' specified.\n"
|
||||
"Use one of 'read committed', 'read uncommitted', "
|
||||
|
||||
Reference in New Issue
Block a user