mirror of
https://github.com/django/django.git
synced 2025-08-04 19:08:28 +00:00
Refs #26022 -- Replaced six.assertRaisesRegex with assertRaisesMessage as appropriate.
This commit is contained in:
parent
253adc2b8a
commit
26ad01719d
23 changed files with 124 additions and 221 deletions
|
@ -12,7 +12,7 @@ from django.db.models import (
|
|||
)
|
||||
from django.test import TestCase
|
||||
from django.test.utils import Approximate, CaptureQueriesContext
|
||||
from django.utils import six, timezone
|
||||
from django.utils import timezone
|
||||
|
||||
from .models import Author, Book, Publisher, Store
|
||||
|
||||
|
@ -906,7 +906,7 @@ class AggregateTestCase(TestCase):
|
|||
self.assertEqual(book['price_sum'], Decimal("99999.80"))
|
||||
|
||||
def test_nonaggregate_aggregation_throws(self):
|
||||
with six.assertRaisesRegex(self, TypeError, 'fail is not an aggregate expression'):
|
||||
with self.assertRaisesMessage(TypeError, 'fail is not an aggregate expression'):
|
||||
Book.objects.aggregate(fail=F('price'))
|
||||
|
||||
def test_nonfield_annotation(self):
|
||||
|
@ -918,7 +918,7 @@ class AggregateTestCase(TestCase):
|
|||
self.assertEqual(book.val, 2)
|
||||
|
||||
def test_missing_output_field_raises_error(self):
|
||||
with six.assertRaisesRegex(self, FieldError, 'Cannot resolve expression type, unknown output_field'):
|
||||
with self.assertRaisesMessage(FieldError, 'Cannot resolve expression type, unknown output_field'):
|
||||
Book.objects.annotate(val=Max(2)).first()
|
||||
|
||||
def test_annotation_expressions(self):
|
||||
|
@ -962,7 +962,7 @@ class AggregateTestCase(TestCase):
|
|||
self.assertEqual(p2, {'avg_price': Approximate(53.39, places=2)})
|
||||
|
||||
def test_combine_different_types(self):
|
||||
with six.assertRaisesRegex(self, FieldError, 'Expression contains mixed types. You must set output_field'):
|
||||
with self.assertRaisesMessage(FieldError, 'Expression contains mixed types. You must set output_field'):
|
||||
Book.objects.annotate(sums=Sum('rating') + Sum('pages') + Sum('price')).get(pk=self.b4.pk)
|
||||
|
||||
b1 = Book.objects.annotate(sums=Sum(F('rating') + F('pages') + F('price'),
|
||||
|
@ -978,11 +978,11 @@ class AggregateTestCase(TestCase):
|
|||
self.assertEqual(b3.sums, Approximate(Decimal("383.69"), places=2))
|
||||
|
||||
def test_complex_aggregations_require_kwarg(self):
|
||||
with six.assertRaisesRegex(self, TypeError, 'Complex annotations require an alias'):
|
||||
with self.assertRaisesMessage(TypeError, 'Complex annotations require an alias'):
|
||||
Author.objects.annotate(Sum(F('age') + F('friends__age')))
|
||||
with six.assertRaisesRegex(self, TypeError, 'Complex aggregates require an alias'):
|
||||
with self.assertRaisesMessage(TypeError, 'Complex aggregates require an alias'):
|
||||
Author.objects.aggregate(Sum('age') / Count('age'))
|
||||
with six.assertRaisesRegex(self, TypeError, 'Complex aggregates require an alias'):
|
||||
with self.assertRaisesMessage(TypeError, 'Complex aggregates require an alias'):
|
||||
Author.objects.aggregate(Sum(1))
|
||||
|
||||
def test_aggregate_over_complex_annotation(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue