summaryrefslogtreecommitdiff
path: root/tests/update_only_fields
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/update_only_fields
parent38988f289f7f5708f5ea85de2d5dfe0d86b23106 (diff)
downloaddjango-a51c4de1945be2225f20fad794cfb52d8f1f9236.tar.gz
Used assertRaisesMessage() to test Django's error messages.
Diffstat (limited to 'tests/update_only_fields')
-rw-r--r--tests/update_only_fields/tests.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/tests/update_only_fields/tests.py b/tests/update_only_fields/tests.py
index 743b5fda8d..58ae94b7cc 100644
--- a/tests/update_only_fields/tests.py
+++ b/tests/update_only_fields/tests.py
@@ -5,6 +5,8 @@ from .models import Account, Employee, Person, Profile, ProxyEmployee
class UpdateOnlyFieldsTests(TestCase):
+ msg = 'The following fields do not exist in this model or are m2m fields: %s'
+
def test_update_fields_basic(self):
s = Person.objects.create(name='Sara', gender='F')
self.assertEqual(s.gender, 'F')
@@ -120,7 +122,7 @@ class UpdateOnlyFieldsTests(TestCase):
a2 = Account.objects.create(num=2)
e1.accounts.set([a1, a2])
- with self.assertRaises(ValueError):
+ with self.assertRaisesMessage(ValueError, self.msg % 'accounts'):
e1.save(update_fields=['accounts'])
def test_update_fields_inheritance(self):
@@ -201,10 +203,12 @@ class UpdateOnlyFieldsTests(TestCase):
def test_update_fields_incorrect_params(self):
s = Person.objects.create(name='Sara', gender='F')
- with self.assertRaises(ValueError):
+ with self.assertRaisesMessage(ValueError, self.msg % 'first_name'):
s.save(update_fields=['first_name'])
- with self.assertRaises(ValueError):
+ # "name" is treated as an iterable so the output is something like
+ # "n, a, m, e" but the order isn't deterministic.
+ with self.assertRaisesMessage(ValueError, self.msg % ''):
s.save(update_fields="name")
def test_empty_update_fields(self):