def test_named_outer_atomic_nesting(self): """ Test that a named outer_atomic raises an error only if nested in enable_named_outer_atomic and inside another atomic. """ if connection.vendor != 'mysql': raise unittest.SkipTest('Only works on MySQL.') outer_atomic(name='abc')(do_nothing)() with atomic(): outer_atomic(name='abc')(do_nothing)() with enable_named_outer_atomic('abc'): outer_atomic(name='abc')(do_nothing)() # Not nested. with atomic(): outer_atomic(name='pqr')(do_nothing)() # Not enabled. with self.assertRaisesRegex(TransactionManagementError, 'Cannot be inside an atomic block.'): with atomic(): outer_atomic(name='abc')(do_nothing)() with enable_named_outer_atomic('abc', 'def'): outer_atomic(name='def')(do_nothing)() # Not nested. with atomic(): outer_atomic(name='pqr')(do_nothing)() # Not enabled. with self.assertRaisesRegex(TransactionManagementError, 'Cannot be inside an atomic block.'): with atomic(): outer_atomic(name='def')(do_nothing)() with self.assertRaisesRegex(TransactionManagementError, 'Cannot be inside an atomic block.'): with outer_atomic(): outer_atomic(name='def')(do_nothing)() with self.assertRaisesRegex(TransactionManagementError, 'Cannot be inside an atomic block.'): with atomic(): outer_atomic(name='abc')(do_nothing)() with self.assertRaisesRegex(TransactionManagementError, 'Cannot be inside an atomic block.'): with outer_atomic(): outer_atomic(name='abc')(do_nothing)()
def test_named_outer_atomic_nesting(self): """ Test that a named outer_atomic raises an error only if nested in enable_named_outer_atomic and inside another atomic. """ outer_atomic(name='abc')(do_nothing)() # pylint: disable=not-callable with atomic(): outer_atomic(name='abc')(do_nothing)() # pylint: disable=not-callable with enable_named_outer_atomic('abc'): outer_atomic(name='abc')(do_nothing)() # pylint: disable=not-callable # Not nested. with atomic(): outer_atomic(name='pqr')(do_nothing)() # pylint: disable=not-callable # Not enabled. with self.assertRaisesRegex(TransactionManagementError, 'Cannot be inside an atomic block.'): with atomic(): outer_atomic(name='abc')(do_nothing)() # pylint: disable=not-callable with enable_named_outer_atomic('abc', 'def'): outer_atomic(name='def')(do_nothing)() # pylint: disable=not-callable # Not nested. with atomic(): outer_atomic(name='pqr')(do_nothing)() # pylint: disable=not-callable # Not enabled. with self.assertRaisesRegex(TransactionManagementError, 'Cannot be inside an atomic block.'): with atomic(): outer_atomic(name='def')(do_nothing)() # pylint: disable=not-callable with self.assertRaisesRegex(TransactionManagementError, 'Cannot be inside an atomic block.'): with outer_atomic(): outer_atomic(name='def')(do_nothing)() # pylint: disable=not-callable with self.assertRaisesRegex(TransactionManagementError, 'Cannot be inside an atomic block.'): with atomic(): outer_atomic(name='abc')(do_nothing)() # pylint: disable=not-callable with self.assertRaisesRegex(TransactionManagementError, 'Cannot be inside an atomic block.'): with outer_atomic(): outer_atomic(name='abc')(do_nothing)() # pylint: disable=not-callable