Exemplo n.º 1
0
    def test_paginator(self):
        search = Search(index=Token.es_doc_type._doc_type.index,
                        doc_type=Token.es_doc_type._doc_type.name)
        search = search.sort('name')

        page_size = 2
        paginator = ESSearchPaginator(search, page_size)

        page = paginator.page(1)

        self.assertTrue(page.has_other_pages)
        self.assertEqual(len(page.hits), page_size)
        self.assertEqual(page.total_count, 3)

        self.assertEqual(page.hits[0]['name'], 'token 0')
        self.assertEqual(page.hits[1]['name'], 'token 1')

        self.assertEqual(page.paginator, paginator)
        self.assertEqual(page.number, 1)
        self.assertIsNotNone(page.response)

        page = paginator.page(2)

        self.assertFalse(page.has_other_pages)
        self.assertEqual(len(page.hits), 1)

        self.assertEqual(page.hits[0]['name'], 'token 2')
Exemplo n.º 2
0
 def paginate_search(self):
     search = self.get_search()
     paginator = ESSearchPaginator(search, self.page_size)
     page_number = self.get_page_number()
     return paginator.page(page_number)
Exemplo n.º 3
0
 def paginate_search(self):
     search = self.get_search()
     paginator = ESSearchPaginator(search, self.page_size)
     page_number = self.get_page_number()
     return paginator.page(page_number)