Used assertRaisesMessage() to test Django's error messages.

This commit is contained in:
Mads Jensen 2017-05-28 21:37:21 +02:00 committed by Tim Graham
parent 38988f289f
commit a51c4de194
69 changed files with 448 additions and 173 deletions

View file

@ -29,7 +29,11 @@ class ManyToManyTests(TestCase):
# Create an Article.
a5 = Article(headline='Django lets you reate Web apps easily')
# You can't associate it with a Publication until it's been saved.
with self.assertRaises(ValueError):
msg = (
'"<Article: Django lets you reate Web apps easily>" needs to have '
'a value for field "id" before this many-to-many relationship can be used.'
)
with self.assertRaisesMessage(ValueError, msg):
getattr(a5, 'publications')
# Save it!
a5.save()