Пример #1
0
    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)], [])
Пример #2
0
    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)
Пример #3
0
    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)
Пример #4
0
    def tests_render_yt_paginator_extra(self):
        def mock_render(template, context):
            return template, context

        req = RequestFactory().get('/?foo_page=1&extra=foo')
        context = {
            'request': req,
        }
        items = list(range(0, 20))
        page = YTPaginator(items, per_page=10).page(1)

        org_render, ttag_paginator.render_to_string = ttag_paginator.render_to_string, mock_render
        try:
            template, context2 = render_paginator(context,
                                                  page,
                                                  page_var='foo_page',
                                                  hashtag="c20")
            self.assertDictEqual(
                context2, {
                    "page": page,
                    "page_var": 'foo_page',
                    "hashtag": '#c20',
                    "extra_query": '&extra=foo'
                })
            self.assertEqual(template, "spirit/paginator/_yt_paginator.html")
        finally:
            ttag_paginator.render_to_string = org_render
Пример #5
0
 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 spirit_tags %}"
                    "{% render_yt_paginator page %}").render(
                        Context({
                            'request': req,
                            'page': page,
                        }))
Пример #6
0
 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": ''
     })
Пример #7
0
    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)], [])
Пример #8
0
    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])
Пример #9
0
 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'
         })
Пример #10
0
    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])
Пример #11
0
 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))
Пример #12
0
 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))