def test_large_end_result_set(self): paginator = Paginator(range(133), 12) self.assertEqual(paginator.page_numbers(), [9, 10, 11, 12, 13]) self.assertEqual(paginator.page_numbers_left(), [9, 10, 11]) self.assertEqual(paginator.page_numbers_right(), [13]) self.assertFalse(paginator.show_end()) self.assertFalse(paginator.needs_end_ellipsis())
def test_small_result_set(self): paginator = Paginator(range(39), 0) self.assertFalse(paginator.show_start()) self.assertFalse(paginator.needs_start_ellipsis()) self.assertFalse(paginator.show_end()) self.assertFalse(paginator.needs_end_ellipsis()) self.assertEqual(paginator.page_numbers_left(), []) self.assertEqual(paginator.page_numbers_right(), [1, 2, 3])
def test_show_end_not_ellipsis(self): paginator = Paginator(range(100), 6) self.assertTrue(paginator.show_start()) self.assertTrue(paginator.needs_start_ellipsis()) self.assertEqual(paginator.page_numbers(), [4, 5, 6, 7, 8]) self.assertEqual(paginator.page_numbers_left(), [4, 5]) self.assertEqual(paginator.page_numbers_right(), [7, 8]) self.assertTrue(paginator.show_end()) self.assertFalse(paginator.needs_end_ellipsis())
def test_middle_page(self): paginator = Paginator(range(100), 4) self.assertTrue(paginator.has_next_page()) self.assertTrue(paginator.has_previous_page()) self.assertEqual(paginator.total_pages(), 10) self.assertEqual(paginator.page_numbers(), [2, 3, 4, 5, 6]) self.assertTrue(paginator.needs_start_ellipsis()) self.assertTrue(paginator.needs_end_ellipsis()) self.assertEqual(paginator.page_numbers_left(), [2, 3]) self.assertEqual(paginator.page_numbers_right(), [5, 6])
def test_last_page(self): paginator = Paginator(range(100), 9) self.assertFalse(paginator.has_next_page()) self.assertTrue(paginator.has_previous_page()) self.assertEqual(paginator.total_pages(), 10) self.assertEqual(paginator.page_numbers(), [5, 6, 7, 8, 9]) self.assertTrue(paginator.needs_start_ellipsis()) self.assertFalse(paginator.needs_end_ellipsis()) self.assertEqual(paginator.page_numbers_left(), [5, 6, 7, 8]) self.assertEqual(paginator.page_numbers_right(), [])
def test_first_page(self): paginator = Paginator(range(100), 0) self.assertTrue(paginator.has_next_page()) self.assertFalse(paginator.has_previous_page()) self.assertEqual(paginator.total_pages(), 10) self.assertEqual(paginator.page_numbers(), [0, 1, 2, 3, 4]) self.assertFalse(paginator.needs_start_ellipsis()) self.assertTrue(paginator.needs_end_ellipsis()) self.assertEqual(paginator.page_numbers_left(), []) self.assertEqual(paginator.page_numbers_right(), [1, 2, 3, 4])