summaryrefslogtreecommitdiff
path: root/tests/transactions
diff options
context:
space:
mode:
authorMads Jensen <mje@inducks.org>2017-05-28 21:37:21 +0200
committerTim Graham <timograham@gmail.com>2017-07-29 19:07:23 -0400
commita51c4de1945be2225f20fad794cfb52d8f1f9236 (patch)
tree36386b70a27cf027a8a491de319c3e59e0d3d0cd /tests/transactions
parent38988f289f7f5708f5ea85de2d5dfe0d86b23106 (diff)
Used assertRaisesMessage() to test Django's error messages.
Diffstat (limited to 'tests/transactions')
-rw-r--r--tests/transactions/tests.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/tests/transactions/tests.py b/tests/transactions/tests.py
index 398a14be4e..7d4d4b777a 100644
--- a/tests/transactions/tests.py
+++ b/tests/transactions/tests.py
@@ -299,20 +299,21 @@ class AtomicMergeTests(TransactionTestCase):
class AtomicErrorsTests(TransactionTestCase):
available_apps = ['transactions']
+ forbidden_atomic_msg = "This is forbidden when an 'atomic' block is active."
def test_atomic_prevents_setting_autocommit(self):
autocommit = transaction.get_autocommit()
with transaction.atomic():
- with self.assertRaises(transaction.TransactionManagementError):
+ with self.assertRaisesMessage(transaction.TransactionManagementError, self.forbidden_atomic_msg):
transaction.set_autocommit(not autocommit)
# Make sure autocommit wasn't changed.
self.assertEqual(connection.autocommit, autocommit)
def test_atomic_prevents_calling_transaction_methods(self):
with transaction.atomic():
- with self.assertRaises(transaction.TransactionManagementError):
+ with self.assertRaisesMessage(transaction.TransactionManagementError, self.forbidden_atomic_msg):
transaction.commit()
- with self.assertRaises(transaction.TransactionManagementError):
+ with self.assertRaisesMessage(transaction.TransactionManagementError, self.forbidden_atomic_msg):
transaction.rollback()
def test_atomic_prevents_queries_in_broken_transaction(self):
@@ -322,7 +323,11 @@ class AtomicErrorsTests(TransactionTestCase):
with self.assertRaises(IntegrityError):
r2.save(force_insert=True)
# The transaction is marked as needing rollback.
- with self.assertRaises(transaction.TransactionManagementError):
+ msg = (
+ "An error occurred in the current transaction. You can't "
+ "execute queries until the end of the 'atomic' block."
+ )
+ with self.assertRaisesMessage(transaction.TransactionManagementError, msg):
r2.save(force_update=True)
self.assertEqual(Reporter.objects.get(pk=r1.pk).last_name, "Haddock")