Example #1
0
class SearchResultPagerTests(unittest.TestCase):
    def setUp(self):
        self.pager = SearchResultPager(5, 100, 1000)
        self.pager_five = SearchResultPager(1, 10, 5)
        self.pager_eight = SearchResultPager(1, 1, 8)

    def tearDown(self):
        del self.pager
        del self.pager_five

    def test_init(self):
        self.assertEquals(5, self.pager.page)
        self.assertEquals(100, self.pager.per_page)
        self.assertEquals(1000, self.pager.total_count)

    def test_pages(self):
        self.assertEquals(10, self.pager.pages)
        self.assertEquals(1, self.pager_five.pages)

    def test_has_prev(self):
        self.assertTrue(self.pager.has_prev)
        self.assertFalse(self.pager_five.has_prev)

    def test_prev(self):
        self.assertEquals(4, self.pager.prev)
        self.assertEquals(None, self.pager_five.prev)

    def test_has_next(self):
        self.assertTrue(self.pager.has_next)
        self.assertFalse(self.pager_five.has_next)

    def test_next(self):
        self.assertEquals(6, self.pager.next)
        self.assertEquals(None, self.pager_five.next)

    def test_iter_all_pages(self):
        pages = list(self.pager.iter_pages())
        self.assertEquals(self.pager.pages, len(pages))
        self.assertEquals(1, pages[0])
        self.assertEquals(10, pages[9])

        pages = list(self.pager_five.iter_pages())
        self.assertEquals(self.pager_five.pages, len(pages))
        self.assertEquals(1, pages[0])
        self.assertListEqual([1, 2, 3, 4, 5, None, 7, 8], list(self.pager_eight.iter_pages()))
Example #2
0
 def setUp(self):
     self.pager = SearchResultPager(5, 100, 1000)
     self.pager_five = SearchResultPager(1, 10, 5)
     self.pager_eight = SearchResultPager(1, 1, 8)