diff options
author | Pablo <pablo22estevez@gmail.com> | 2022-12-02 23:04:42 -0300 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-12-05 10:46:33 +0100 |
commit | 48531f53ae9c5781094c91b6aaec204920359018 (patch) | |
tree | 544a3f9bd1ecc0f779962067456bb18cf6506a8b /tests/transactions | |
parent | 344593893b6fc5fdda45a74013fc8622401c5058 (diff) | |
download | django-48531f53ae9c5781094c91b6aaec204920359018.tar.gz |
Improved test coverage for django.db.transaction.
Diffstat (limited to 'tests/transactions')
-rw-r--r-- | tests/transactions/tests.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/transactions/tests.py b/tests/transactions/tests.py index bdf912653c..1f2634224b 100644 --- a/tests/transactions/tests.py +++ b/tests/transactions/tests.py @@ -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.""" |