mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Refs #32508 -- Raised Type/ValueError instead of using "assert" in django.db.models.
Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
This commit is contained in:
committed by
Mariusz Felisiak
parent
08f0778885
commit
f479df7f8d
@@ -417,9 +417,10 @@ class Queries1Tests(TestCase):
|
||||
def test_heterogeneous_qs_combination(self):
|
||||
# Combining querysets built on different models should behave in a well-defined
|
||||
# fashion. We raise an error.
|
||||
with self.assertRaisesMessage(AssertionError, 'Cannot combine queries on two different base models.'):
|
||||
msg = 'Cannot combine queries on two different base models.'
|
||||
with self.assertRaisesMessage(TypeError, msg):
|
||||
Author.objects.all() & Tag.objects.all()
|
||||
with self.assertRaisesMessage(AssertionError, 'Cannot combine queries on two different base models.'):
|
||||
with self.assertRaisesMessage(TypeError, msg):
|
||||
Author.objects.all() | Tag.objects.all()
|
||||
|
||||
def test_ticket3141(self):
|
||||
@@ -1226,10 +1227,11 @@ class Queries3Tests(TestCase):
|
||||
# This shouldn't create an infinite loop.
|
||||
self.assertQuerysetEqual(Valid.objects.all(), [])
|
||||
|
||||
def test_ticket8683(self):
|
||||
def test_datetimes_invalid_field(self):
|
||||
# An error should be raised when QuerySet.datetimes() is passed the
|
||||
# wrong type of field.
|
||||
with self.assertRaisesMessage(AssertionError, "'name' isn't a DateField, TimeField, or DateTimeField."):
|
||||
msg = "'name' isn't a DateField, TimeField, or DateTimeField."
|
||||
with self.assertRaisesMessage(TypeError, msg):
|
||||
Item.objects.datetimes('name', 'month')
|
||||
|
||||
def test_ticket22023(self):
|
||||
@@ -2405,13 +2407,17 @@ class QuerySetSupportsPythonIdioms(TestCase):
|
||||
|
||||
def test_slicing_negative_indexing_not_supported_for_single_element(self):
|
||||
"""hint: inverting your ordering might do what you need"""
|
||||
with self.assertRaisesMessage(AssertionError, "Negative indexing is not supported."):
|
||||
msg = 'Negative indexing is not supported.'
|
||||
with self.assertRaisesMessage(ValueError, msg):
|
||||
Article.objects.all()[-1]
|
||||
|
||||
def test_slicing_negative_indexing_not_supported_for_range(self):
|
||||
"""hint: inverting your ordering might do what you need"""
|
||||
with self.assertRaisesMessage(AssertionError, "Negative indexing is not supported."):
|
||||
msg = 'Negative indexing is not supported.'
|
||||
with self.assertRaisesMessage(ValueError, msg):
|
||||
Article.objects.all()[0:-5]
|
||||
with self.assertRaisesMessage(ValueError, msg):
|
||||
Article.objects.all()[-1:]
|
||||
|
||||
def test_invalid_index(self):
|
||||
msg = 'QuerySet indices must be integers or slices, not str.'
|
||||
|
||||
Reference in New Issue
Block a user