summaryrefslogtreecommitdiff
path: root/tests/queries/tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/queries/tests.py')
-rw-r--r--tests/queries/tests.py47
1 files changed, 12 insertions, 35 deletions
diff --git a/tests/queries/tests.py b/tests/queries/tests.py
index 376208c62d..f1acd69067 100644
--- a/tests/queries/tests.py
+++ b/tests/queries/tests.py
@@ -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)