Пример #1
0
    def test_has_next(self):

        pager = UrlPaginator('/search', list(range(11)), 10)
        self.assertTrue(pager.has_next())

        pager = UrlPaginator('/search', object_list=list(range(10)), per_page=10)
        self.assertFalse(pager.has_next())
Пример #2
0
    def test_pages(self):
        pager = UrlPaginator('/search', list(range(50)), 10)
        pages = pager.pages()
        self.assertEqual(4, len(pages))

        pages = pager.page(2).pages()
        self.assertEqual(5, len(pages))

        pages = pager.page(5).pages()
        self.assertEqual(4, len(pages))
        self.assertEqual([1,2,3,4], [i['number'] for i in pager.pages()])
Пример #3
0
 def test_iterable(self):
     pager = UrlPaginator('/search',
                          object_list=list(range(20)),
                          per_page=10)
     i = iter(pager)
     self.assertEqual(0, six.next(i))
     self.assertEqual(list(range(10)), list(pager))
Пример #4
0
    def test_has_next(self):

        pager = UrlPaginator('/search', list(range(11)), 10)
        self.assertTrue(pager.has_next())

        pager = UrlPaginator('/search',
                             object_list=list(range(10)),
                             per_page=10)
        self.assertFalse(pager.has_next())
Пример #5
0
    def test_pages(self):
        pager = UrlPaginator('/search', list(range(50)), 10)
        pages = pager.pages()
        self.assertEqual(4, len(pages))

        pages = pager.page(2).pages()
        self.assertEqual(5, len(pages))

        pages = pager.page(5).pages()
        self.assertEqual(4, len(pages))
        self.assertEqual([1, 2, 3, 4], [i['number'] for i in pager.pages()])
Пример #6
0
 def test_prev(self):
     pager = UrlPaginator('/search?page=2', object_list=list(range(20)), per_page=10)
     n = pager.prev()
     self.assertEqual(1, n['number'])
Пример #7
0
 def test_next(self):
     pager = UrlPaginator('/search', object_list=list(range(20)), per_page=10)
     n = pager.next()
     self.assertEqual(2, n['number'])
Пример #8
0
    def test_has_page_on_non_first_page(self):
        pager = UrlPaginator('/search', list(range(50)), 10)
        second = pager.pages()[1]

        self.assertEqual("/search?page=2", second['url'])
        self.assertEqual(2, second['number'])
Пример #9
0
 def test_no_page_on_first_page(self):
     pager = UrlPaginator('/search', list(range(50)), 10)
     first = pager.pages()[0]
     self.assertEqual("/search", first['url'])
     self.assertEqual("", first['query'])
Пример #10
0
 def test_prev(self):
     pager = UrlPaginator('/search?page=2',
                          object_list=list(range(20)),
                          per_page=10)
     n = pager.prev()
     self.assertEqual(1, n['number'])
Пример #11
0
 def test_next(self):
     pager = UrlPaginator('/search',
                          object_list=list(range(20)),
                          per_page=10)
     n = pager.next()
     self.assertEqual(2, n['number'])
Пример #12
0
    def test_has_page_on_non_first_page(self):
        pager = UrlPaginator('/search', list(range(50)), 10)
        second = pager.pages()[1]

        self.assertEqual("/search?page=2", second['url'])
        self.assertEqual(2, second['number'])
Пример #13
0
 def test_no_page_on_first_page(self):
     pager = UrlPaginator('/search', list(range(50)), 10)
     first = pager.pages()[0]
     self.assertEqual("/search", first['url'])
     self.assertEqual("", first['query'])