summaryrefslogtreecommitdiff
path: root/tests/transactions
diff options
context:
space:
mode:
authorKrzysztof Jagiello <me@kjagiello.com>2021-09-30 19:13:56 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-11-12 13:05:56 +0100
commit8d9827c06ce1592cca111e7eafb9ebe0153104ef (patch)
tree23b1a84959500c4ce21229a6f10ede06595379f0 /tests/transactions
parentadb4100e58d9ea073ee8caa454bb7c885b6a83ed (diff)
Fixed #33161 -- Enabled durability check for nested atomic blocks in TestCase.
Co-Authored-By: Adam Johnson <me@adamj.eu>
Diffstat (limited to 'tests/transactions')
-rw-r--r--tests/transactions/tests.py48
1 files changed, 12 insertions, 36 deletions
diff --git a/tests/transactions/tests.py b/tests/transactions/tests.py
index ccad5ca76c..dda4b3680a 100644
--- a/tests/transactions/tests.py
+++ b/tests/transactions/tests.py
@@ -501,7 +501,7 @@ class NonAutocommitTests(TransactionTestCase):
Reporter.objects.create(first_name="Tintin")
-class DurableTests(TransactionTestCase):
+class DurableTestsBase:
available_apps = ['transactions']
def test_commit(self):
@@ -533,42 +533,18 @@ class DurableTests(TransactionTestCase):
with transaction.atomic(durable=True):
pass
-
-class DisableDurabiltityCheckTests(TestCase):
- """
- TestCase runs all tests in a transaction by default. Code using
- durable=True would always fail when run from TestCase. This would mean
- these tests would be forced to use the slower TransactionTestCase even when
- not testing durability. For this reason, TestCase disables the durability
- check.
- """
- available_apps = ['transactions']
-
- def test_commit(self):
+ def test_sequence_of_durables(self):
with transaction.atomic(durable=True):
- reporter = Reporter.objects.create(first_name='Tintin')
- self.assertEqual(Reporter.objects.get(), reporter)
-
- def test_nested_outer_durable(self):
+ reporter = Reporter.objects.create(first_name='Tintin 1')
+ self.assertEqual(Reporter.objects.get(first_name='Tintin 1'), reporter)
with transaction.atomic(durable=True):
- reporter1 = Reporter.objects.create(first_name='Tintin')
- with transaction.atomic():
- reporter2 = Reporter.objects.create(
- first_name='Archibald',
- last_name='Haddock',
- )
- self.assertSequenceEqual(Reporter.objects.all(), [reporter2, reporter1])
+ reporter = Reporter.objects.create(first_name='Tintin 2')
+ self.assertEqual(Reporter.objects.get(first_name='Tintin 2'), reporter)
- def test_nested_both_durable(self):
- with transaction.atomic(durable=True):
- # Error is not raised.
- with transaction.atomic(durable=True):
- reporter = Reporter.objects.create(first_name='Tintin')
- self.assertEqual(Reporter.objects.get(), reporter)
- def test_nested_inner_durable(self):
- with transaction.atomic():
- # Error is not raised.
- with transaction.atomic(durable=True):
- reporter = Reporter.objects.create(first_name='Tintin')
- self.assertEqual(Reporter.objects.get(), reporter)
+class DurableTransactionTests(DurableTestsBase, TransactionTestCase):
+ pass
+
+
+class DurableTests(DurableTestsBase, TestCase):
+ pass