mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Refs #26022 -- Replaced six.assertRaisesRegex with assertRaisesMessage as appropriate.
This commit is contained in:
@@ -1362,9 +1362,8 @@ class Queries4Tests(BaseQuerysetTest):
|
||||
|
||||
def test_ticket11811(self):
|
||||
unsaved_category = NamedCategory(name="Other")
|
||||
with six.assertRaisesRegex(self, ValueError,
|
||||
'Unsaved model instance <NamedCategory: Other> '
|
||||
'cannot be used in an ORM query.'):
|
||||
msg = 'Unsaved model instance <NamedCategory: Other> cannot be used in an ORM query.'
|
||||
with self.assertRaisesMessage(ValueError, msg):
|
||||
Tag.objects.filter(pk=self.t1.pk).update(category=unsaved_category)
|
||||
|
||||
def test_ticket14876(self):
|
||||
@@ -2321,48 +2320,26 @@ class QuerySetSupportsPythonIdioms(TestCase):
|
||||
"<Article: Article 7>"])
|
||||
|
||||
def test_slicing_cannot_filter_queryset_once_sliced(self):
|
||||
six.assertRaisesRegex(
|
||||
self,
|
||||
AssertionError,
|
||||
"Cannot filter a query once a slice has been taken.",
|
||||
Article.objects.all()[0:5].filter,
|
||||
id=1,
|
||||
)
|
||||
with self.assertRaisesMessage(AssertionError, "Cannot filter a query once a slice has been taken."):
|
||||
Article.objects.all()[0:5].filter(id=1, )
|
||||
|
||||
def test_slicing_cannot_reorder_queryset_once_sliced(self):
|
||||
six.assertRaisesRegex(
|
||||
self,
|
||||
AssertionError,
|
||||
"Cannot reorder a query once a slice has been taken.",
|
||||
Article.objects.all()[0:5].order_by,
|
||||
'id',
|
||||
)
|
||||
with self.assertRaisesMessage(AssertionError, "Cannot reorder a query once a slice has been taken."):
|
||||
Article.objects.all()[0:5].order_by('id', )
|
||||
|
||||
def test_slicing_cannot_combine_queries_once_sliced(self):
|
||||
six.assertRaisesRegex(
|
||||
self,
|
||||
AssertionError,
|
||||
"Cannot combine queries once a slice has been taken.",
|
||||
lambda: Article.objects.all()[0:1] & Article.objects.all()[4:5]
|
||||
)
|
||||
with self.assertRaisesMessage(AssertionError, "Cannot combine queries once a slice has been taken."):
|
||||
Article.objects.all()[0:1] & Article.objects.all()[4:5]
|
||||
|
||||
def test_slicing_negative_indexing_not_supported_for_single_element(self):
|
||||
"""hint: inverting your ordering might do what you need"""
|
||||
six.assertRaisesRegex(
|
||||
self,
|
||||
AssertionError,
|
||||
"Negative indexing is not supported.",
|
||||
lambda: Article.objects.all()[-1]
|
||||
)
|
||||
with self.assertRaisesMessage(AssertionError, "Negative indexing is not supported."):
|
||||
Article.objects.all()[-1]
|
||||
|
||||
def test_slicing_negative_indexing_not_supported_for_range(self):
|
||||
"""hint: inverting your ordering might do what you need"""
|
||||
six.assertRaisesRegex(
|
||||
self,
|
||||
AssertionError,
|
||||
"Negative indexing is not supported.",
|
||||
lambda: Article.objects.all()[0:-5]
|
||||
)
|
||||
with self.assertRaisesMessage(AssertionError, "Negative indexing is not supported."):
|
||||
Article.objects.all()[0:-5]
|
||||
|
||||
def test_can_get_number_of_items_in_queryset_using_standard_len(self):
|
||||
self.assertEqual(len(Article.objects.filter(name__exact='Article 1')), 1)
|
||||
|
||||
Reference in New Issue
Block a user