Tests proper behavior of a paginator page __getitem__ (queryset evaluation, slicing, exception raised).
(self)
| 840 | self.assertEqual(9, await p.aend_index()) |
| 841 | |
| 842 | def test_page_getitem(self): |
| 843 | """ |
| 844 | Tests proper behavior of a paginator page __getitem__ (queryset |
| 845 | evaluation, slicing, exception raised). |
| 846 | """ |
| 847 | paginator = Paginator(Article.objects.order_by("id"), 5) |
| 848 | p = paginator.page(1) |
| 849 | |
| 850 | # object_list queryset is not evaluated by an invalid __getitem__ call. |
| 851 | # (this happens from the template engine when using e.g.: |
| 852 | # {% page_obj.has_previous %}). |
| 853 | self.assertIsNone(p.object_list._result_cache) |
| 854 | msg = "Page indices must be integers or slices, not str." |
| 855 | with self.assertRaisesMessage(TypeError, msg): |
| 856 | p["has_previous"] |
| 857 | self.assertIsNone(p.object_list._result_cache) |
| 858 | self.assertNotIsInstance(p.object_list, list) |
| 859 | |
| 860 | # Make sure slicing the Page object with numbers and slice objects |
| 861 | # work. |
| 862 | self.assertEqual(p[0], self.articles[0]) |
| 863 | self.assertSequenceEqual(p[slice(2)], self.articles[:2]) |
| 864 | # After __getitem__ is called, object_list is a list |
| 865 | self.assertIsInstance(p.object_list, list) |
| 866 | |
| 867 | async def test_page_getitem_async(self): |
| 868 | paginator = AsyncPaginator(Article.objects.order_by("id"), 5) |
nothing calls this directly
no test coverage detected