Exemplo n.º 1
0
    def test_table_page_range_lazy(self):
        paginator = LazyPaginator(range(1, 1000), 10)

        self.assertEqual(table_page_range(paginator.page(1), paginator),
                         range(1, 3))
        self.assertEqual(table_page_range(paginator.page(10), paginator),
                         [1, "...", 4, 5, 6, 7, 8, 9, 10, 11])
    def test_compare_to_default_paginator(self):
        objects = list(range(1, 1000))

        paginator = Paginator(objects, 10)
        lazy_paginator = LazyPaginator(objects, 10)
        self.assertEqual(paginator.page(1).object_list, lazy_paginator.page(1).object_list)
        self.assertEqual(paginator.page(10).object_list, lazy_paginator.page(10).object_list)
        self.assertEqual(paginator.page(100).object_list, lazy_paginator.page(100).object_list)
Exemplo n.º 3
0
    def test_lookahead(self):
        objects = list(range(1, 1000))
        paginator = LazyPaginator(objects, 10, look_ahead=3)

        self.assertEqual(paginator.look_ahead, 3)
        self.assertEqual(paginator.page(1).object_list, list(range(1, 11)))
        self.assertEqual(paginator.num_pages, 4)

        self.assertEqual(paginator.page(98).object_list, list(range(971, 981)))
        self.assertEqual(paginator.num_pages, 100)
    def test_lookahead(self):
        objects = list(range(1, 1000))
        paginator = LazyPaginator(objects, 10, look_ahead=3)

        self.assertEqual(paginator.look_ahead, 3)
        self.assertEqual(paginator.page(1).object_list, list(range(1, 11)))
        self.assertEqual(paginator.num_pages, 4)

        self.assertEqual(paginator.page(98).object_list, list(range(971, 981)))
        self.assertEqual(paginator.num_pages, 100)
Exemplo n.º 5
0
    def test_number_is_none(self):
        """
        When number=None is supplied, the paginator should serve its first page.
        """
        objects = list(range(1, 1000))
        paginator = LazyPaginator(objects, 10, look_ahead=3)
        self.assertEqual(paginator.page(None).object_list, list(range(1, 11)))
        self.assertEqual(paginator.num_pages, 4)

        objects = list(range(1, 20))
        paginator = LazyPaginator(objects, 10, look_ahead=3)
        self.assertEqual(paginator.page(None).object_list, list(range(1, 11)))
Exemplo n.º 6
0
    def test_compare_to_default_paginator(self):
        objects = list(range(1, 1000))

        paginator = Paginator(objects, 10)
        lazy_paginator = LazyPaginator(objects, 10)
        self.assertEqual(
            paginator.page(1).object_list,
            lazy_paginator.page(1).object_list)
        self.assertEqual(
            paginator.page(10).object_list,
            lazy_paginator.page(10).object_list)
        self.assertEqual(
            paginator.page(100).object_list,
            lazy_paginator.page(100).object_list)
Exemplo n.º 7
0
    def test_table_page_range_lazy_last_page(self):
        paginator = LazyPaginator(range(1, 1000), 10)

        self.assertEqual(
            table_page_range(paginator.page(100), paginator),
            [1, "...", 93, 94, 95, 96, 97, 98, 99, 100],
        )
Exemplo n.º 8
0
    def test_no_count_call(self):
        paginator = LazyPaginator(FakeQuerySet(), 10)
        # num_pages initially is None, but is page_number + 1 after requesting a page.
        self.assertEqual(paginator.num_pages, None)

        paginator.page(1)
        self.assertEqual(paginator.num_pages, 2)
        paginator.page(3)
        self.assertEqual(paginator.num_pages, 4)

        paginator.page(1.0)
        # and again decreases when a lower page nu
        self.assertEqual(paginator.num_pages, 2)

        with self.assertRaises(PageNotAnInteger):
            paginator.page(1.5)

        with self.assertRaises(EmptyPage):
            paginator.page(-1)

        with self.assertRaises(NotImplementedError):
            paginator.count()

        with self.assertRaises(NotImplementedError):
            paginator.page_range()

        # last page
        last_page_number = 10**5
        paginator.page(last_page_number)

        with self.assertRaises(EmptyPage):
            paginator.page(last_page_number + 1)
    def test_no_count_call(self):
        paginator = LazyPaginator(FakeQuerySet(), 10)
        # num_pages initially is None, but is page_number + 1 after requesting a page.
        self.assertEqual(paginator.num_pages, None)

        paginator.page(1)
        self.assertEqual(paginator.num_pages, 2)
        paginator.page(3)
        self.assertEqual(paginator.num_pages, 4)

        paginator.page(1.0)
        # and again decreases when a lower page nu
        self.assertEqual(paginator.num_pages, 2)

        with self.assertRaises(PageNotAnInteger):
            paginator.page(1.5)

        with self.assertRaises(EmptyPage):
            paginator.page(-1)

        with self.assertRaises(NotImplementedError):
            paginator.count()

        with self.assertRaises(NotImplementedError):
            paginator.page_range()

        # last page
        last_page_number = 10 ** 5
        paginator.page(last_page_number)

        with self.assertRaises(EmptyPage):
            paginator.page(last_page_number + 1)
Exemplo n.º 10
0
    def test_table_page_range_lazy_beginning(self):
        paginator = LazyPaginator(range(1, 1000), 10)

        self.assertEqual(table_page_range(paginator.page(1), paginator), range(1, 3))