diff options
author | Mads Jensen <mje@inducks.org> | 2017-05-28 21:37:21 +0200 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2017-07-29 19:07:23 -0400 |
commit | a51c4de1945be2225f20fad794cfb52d8f1f9236 (patch) | |
tree | 36386b70a27cf027a8a491de319c3e59e0d3d0cd /tests/many_to_one | |
parent | 38988f289f7f5708f5ea85de2d5dfe0d86b23106 (diff) | |
download | django-a51c4de1945be2225f20fad794cfb52d8f1f9236.tar.gz |
Used assertRaisesMessage() to test Django's error messages.
Diffstat (limited to 'tests/many_to_one')
-rw-r--r-- | tests/many_to_one/tests.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/tests/many_to_one/tests.py b/tests/many_to_one/tests.py index 0382a9a45e..aab050234c 100644 --- a/tests/many_to_one/tests.py +++ b/tests/many_to_one/tests.py @@ -406,7 +406,8 @@ class ManyToOneTests(TestCase): self.assertEqual(a3.reporter.id, self.r2.id) # Get should respect explicit foreign keys as well. - with self.assertRaises(MultipleObjectsReturned): + msg = 'get() returned more than one Article -- it returned 2!' + with self.assertRaisesMessage(MultipleObjectsReturned, msg): Article.objects.get(reporter_id=self.r.id) self.assertEqual( repr(a3), @@ -484,7 +485,11 @@ class ManyToOneTests(TestCase): setattr(c, "parent", None) # You also can't assign an object of the wrong type here - with self.assertRaises(ValueError): + msg = ( + 'Cannot assign "<First: First object (1)>": "Child.parent" must ' + 'be a "Parent" instance.' + ) + with self.assertRaisesMessage(ValueError, msg): setattr(c, "parent", First(id=1, second=1)) # You can assign None to Child.parent during object creation. @@ -550,7 +555,8 @@ class ManyToOneTests(TestCase): p = Parent.objects.create(name="Parent") c = Child.objects.create(name="Child", parent=p) - with self.assertRaises(ValueError): + msg = 'Cannot assign "%r": "Child.parent" must be a "Parent" instance.' % c + with self.assertRaisesMessage(ValueError, msg): Child.objects.create(name="Grandchild", parent=c) def test_fk_instantiation_outside_model(self): |