mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Improved error message when index in __getitem__() is invalid.
This commit is contained in:
parent
8323691de0
commit
d89053585e
6 changed files with 28 additions and 4 deletions
|
@ -2436,6 +2436,11 @@ class QuerySetSupportsPythonIdioms(TestCase):
|
|||
with self.assertRaisesMessage(AssertionError, "Negative indexing is not supported."):
|
||||
Article.objects.all()[0:-5]
|
||||
|
||||
def test_invalid_index(self):
|
||||
msg = 'QuerySet indices must be integers or slices, not str.'
|
||||
with self.assertRaisesMessage(TypeError, msg):
|
||||
Article.objects.all()['foo']
|
||||
|
||||
def test_can_get_number_of_items_in_queryset_using_standard_len(self):
|
||||
self.assertEqual(len(Article.objects.filter(name__exact='Article 1')), 1)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue