1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Improved test coverage for django.db.transaction.

This commit is contained in:
Pablo
2022-12-02 23:04:42 -03:00
committed by Mariusz Felisiak
parent 344593893b
commit 48531f53ae
4 changed files with 41 additions and 0 deletions

View File

@@ -226,6 +226,22 @@ class AtomicTests(TransactionTestCase):
transaction.savepoint_rollback(sid)
self.assertSequenceEqual(Reporter.objects.all(), [reporter])
@skipUnlessDBFeature("can_release_savepoints")
def test_failure_on_exit_transaction(self):
with transaction.atomic():
with self.assertRaises(DatabaseError):
with transaction.atomic():
Reporter.objects.create(last_name="Tintin")
self.assertEqual(len(Reporter.objects.all()), 1)
# Incorrect savepoint id to provoke a database error.
connection.savepoint_ids.append("12")
with self.assertRaises(transaction.TransactionManagementError):
len(Reporter.objects.all())
self.assertIs(connection.needs_rollback, True)
if connection.savepoint_ids:
connection.savepoint_ids.pop()
self.assertSequenceEqual(Reporter.objects.all(), [])
class AtomicInsideTransactionTests(AtomicTests):
"""All basic tests for atomic should also pass within an existing transaction."""