1
0
mirror of https://github.com/django/django.git synced 2025-10-23 21:59:11 +00:00

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

@@ -32,11 +32,12 @@ class NullQueriesTests(TestCase):
self.assertSequenceEqual(Choice.objects.exclude(choice=None).order_by('id'), [c1, c2])
# Valid query, but fails because foo isn't a keyword
with self.assertRaises(FieldError):
msg = "Cannot resolve keyword 'foo' into field. Choices are: choice, id, poll, poll_id"
with self.assertRaisesMessage(FieldError, msg):
Choice.objects.filter(foo__exact=None)
# Can't use None on anything other than __exact and __iexact
with self.assertRaises(ValueError):
with self.assertRaisesMessage(ValueError, 'Cannot use None as a query value'):
Choice.objects.filter(id__gt=None)
# Related managers use __exact=None implicitly if the object hasn't been saved.