Improved error message when index in __getitem__() is invalid.

This commit is contained in:
Jon Dufresne 2019-07-19 13:55:32 -07:00 committed by Mariusz Felisiak
parent 8323691de0
commit d89053585e
6 changed files with 28 additions and 4 deletions

View file

@ -366,7 +366,8 @@ class ModelPaginationTests(TestCase):
# Make sure object_list queryset is not evaluated by an invalid __getitem__ call.
# (this happens from the template engine when using eg: {% page_obj.has_previous %})
self.assertIsNone(p.object_list._result_cache)
with self.assertRaises(TypeError):
msg = 'Page indices must be integers or slices, not str.'
with self.assertRaisesMessage(TypeError, msg):
p['has_previous']
self.assertIsNone(p.object_list._result_cache)
self.assertNotIsInstance(p.object_list, list)