def tests_yt_paginator_num_pages(self):
        yt_paginator = YTPaginator(self.queryset, per_page=10)
        page = yt_paginator.page(1)

        for page_num in range(1, 30 + 1):
            page._num_pages = None
            page._max_pages = page_num
            self.assertEqual(page.num_pages, page_num)

        page._num_pages = None
        page._max_pages = 8
        self.assertEqual(page.num_pages, 8)

        page._num_pages = None
        page._max_pages = 3000
        self.assertEqual(page.num_pages, 30)
 def tests_render_yt_paginator_extra(self):
     req = RequestFactory().get('/?foo_page=1&extra=foo')
     context = {'request': req, }
     items = list(range(0, 20))
     page = YTPaginator(items, per_page=10).page(1)
     res = render_yt_paginator(context, page, page_var='foo_page', hashtag="c20")
     self.assertDictEqual(res, {"page": page,
                                "page_var": 'foo_page',
                                "hashtag": '#c20',
                                "extra_query": '&extra=foo'})
 def tests_render_yt_paginator(self):
     req = RequestFactory().get('/')
     context = {'request': req, }
     items = list(range(0, 20))
     page = YTPaginator(items, per_page=10).page(1)
     res = render_yt_paginator(context, page)
     self.assertDictEqual(res, {"page": page,
                                "page_var": 'page',
                                "hashtag": '',
                                "extra_query": ''})
 def tests_render_yt_paginator_tag(self):
     """
     Minimal test to check it works
     """
     req = RequestFactory().get('/')
     items = list(range(0, 20))
     page = YTPaginator(items, per_page=10).page(1)
     out = Template(
         "{% load foro_tags %}"
         "{% render_yt_paginator page %}"
     ).render(Context({'request': req, 'page': page, }))
    def test_yt_paginator_page(self):
        yt_paginator = YTPaginator(self.queryset, per_page=10)
        page = yt_paginator.page(1)
        self.assertEqual(page.number, 1)
        self.assertListEqual([i for i in page], list(self.queryset[:10]))

        # empty first page
        yt_paginator = YTPaginator(self.queryset.none(), per_page=10)
        self.assertListEqual([i for i in yt_paginator.page(1)], [])
    def test_yt_paginator_page_range(self):
        # 10 pages
        yt_paginator = YTPaginator(list(range(0, 100)), per_page=10)

        page = yt_paginator.page(1)
        self.assertListEqual(list(page.page_range), [1, 2, 3, 4, 5, 6, 7])

        page = yt_paginator.page(4)
        self.assertListEqual(list(page.page_range), [1, 2, 3, 4, 5, 6, 7])

        page = yt_paginator.page(7)
        self.assertListEqual(list(page.page_range), [4, 5, 6, 7, 8, 9, 10])

        page = yt_paginator.page(10)
        self.assertListEqual(list(page.page_range), [4, 5, 6, 7, 8, 9, 10])

        # 2 pages
        yt_paginator = YTPaginator(list(range(0, 20)), per_page=10)

        page = yt_paginator.page(1)
        self.assertListEqual(list(page.page_range), [1, 2])

        page = yt_paginator.page(2)
        self.assertListEqual(list(page.page_range), [1, 2])
 def test_yt_paginator_page_invalid(self):
     yt_paginator = YTPaginator(self.queryset, per_page=10)
     self.assertRaises(InvalidPage, lambda: yt_paginator.page("one"))
     self.assertRaises(InvalidPage, lambda: yt_paginator.page(-1))
     self.assertRaises(InvalidPage, lambda: yt_paginator.page(5000))