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:
@@ -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."""
|
||||
|
||||
Reference in New Issue
Block a user