diff options
| author | Daniyal <abbasi.daniyal98@gmail.com> | 2021-03-24 11:15:08 +0530 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-07-15 11:43:33 +0200 |
| commit | f479df7f8d03ab767bb5e5d655243191087d6432 (patch) | |
| tree | bf6f248ad7938a0d9f77ea616a59fba2d5a8befb /tests/queries | |
| parent | 08f077888548a951f01b454d0db08d9407f7f0aa (diff) | |
Refs #32508 -- Raised Type/ValueError instead of using "assert" in django.db.models.
Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
Diffstat (limited to 'tests/queries')
| -rw-r--r-- | tests/queries/tests.py | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/tests/queries/tests.py b/tests/queries/tests.py index ac4e8849c4..fa87e7859c 100644 --- a/tests/queries/tests.py +++ b/tests/queries/tests.py @@ -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.' |
