mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Used assertRaisesMessage() to test Django's error messages.
This commit is contained in:
@@ -118,7 +118,11 @@ class EarliestOrLatestTests(TestCase):
|
||||
# "get_latest_by" set -- just pass in the field name manually.
|
||||
Person.objects.create(name="Ralph", birthday=datetime(1950, 1, 1))
|
||||
p2 = Person.objects.create(name="Stephanie", birthday=datetime(1960, 2, 3))
|
||||
with self.assertRaises(AssertionError):
|
||||
msg = (
|
||||
"earliest() and latest() require either a field_name parameter or "
|
||||
"'get_latest_by' in the model"
|
||||
)
|
||||
with self.assertRaisesMessage(AssertionError, msg):
|
||||
Person.objects.latest()
|
||||
self.assertEqual(Person.objects.latest("birthday"), p2)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user