1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +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

@@ -97,16 +97,18 @@ class DistinctOnTests(TestCase):
def test_distinct_not_implemented_checks(self):
# distinct + annotate not allowed
with self.assertRaises(NotImplementedError):
msg = 'annotate() + distinct(fields) is not implemented.'
with self.assertRaisesMessage(NotImplementedError, msg):
Celebrity.objects.annotate(Max('id')).distinct('id')[0]
with self.assertRaises(NotImplementedError):
with self.assertRaisesMessage(NotImplementedError, msg):
Celebrity.objects.distinct('id').annotate(Max('id'))[0]
# However this check is done only when the query executes, so you
# can use distinct() to remove the fields before execution.
Celebrity.objects.distinct('id').annotate(Max('id')).distinct()[0]
# distinct + aggregate not allowed
with self.assertRaises(NotImplementedError):
msg = 'aggregate() + distinct(fields) not implemented.'
with self.assertRaisesMessage(NotImplementedError, msg):
Celebrity.objects.distinct('id').aggregate(Max('id'))
def test_distinct_on_in_ordered_subquery(self):