MCPcopy
hub / github.com/django/django / test_merged_outer_rollback

Method test_merged_outer_rollback

tests/transactions/tests.py:280–302  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

278 available_apps = ["transactions"]
279
280 def test_merged_outer_rollback(self):
281 with transaction.atomic():
282 Reporter.objects.create(first_name="Tintin")
283 with transaction.atomic(savepoint=False):
284 Reporter.objects.create(first_name="Archibald", last_name="Haddock")
285 with self.assertRaisesMessage(Exception, "Oops"):
286 with transaction.atomic(savepoint=False):
287 Reporter.objects.create(first_name="Calculus")
288 raise Exception("Oops, that's his last name")
289 # The third insert couldn't be roll back. Temporarily mark the
290 # connection as not needing rollback to check it.
291 self.assertTrue(transaction.get_rollback())
292 transaction.set_rollback(False)
293 self.assertEqual(Reporter.objects.count(), 3)
294 transaction.set_rollback(True)
295 # The second insert couldn't be roll back. Temporarily mark the
296 # connection as not needing rollback to check it.
297 self.assertTrue(transaction.get_rollback())
298 transaction.set_rollback(False)
299 self.assertEqual(Reporter.objects.count(), 3)
300 transaction.set_rollback(True)
301 # The first block has a savepoint and must roll back.
302 self.assertSequenceEqual(Reporter.objects.all(), [])
303
304 def test_merged_inner_savepoint_rollback(self):
305 with transaction.atomic():

Callers

nothing calls this directly

Calls 6

assertRaisesMessageMethod · 0.80
get_rollbackMethod · 0.80
set_rollbackMethod · 0.80
createMethod · 0.45
countMethod · 0.45
allMethod · 0.45

Tested by

no test coverage detected