Esempio n. 1
0
 def test_get_page_from_search_es_wrong_page(self, mock_es_count):
     # Not an integer
     page = helpers.get_page_from_search(self.es_search, {"page": "text"})
     self.assertEqual(page.paginator.num_pages, 10)
     self.assertEqual(page.number, 1)
     self.assertEqual(page.object_list.to_dict(), {"from": 0, "size": 10})
     # Empty page
     page = helpers.get_page_from_search(self.es_search, {"page": "11"})
     self.assertEqual(page.paginator.num_pages, 10)
     self.assertEqual(page.number, 10)
     self.assertEqual(page.object_list.to_dict(), {"from": 90, "size": 10})
Esempio n. 2
0
 def test_get_page_from_search_orm_wrong_page(self, mock_orm_count):
     # Not an integer
     page = helpers.get_page_from_search(self.orm_query_set, {"page": "text"})
     self.assertEqual(page.paginator.num_pages, 10)
     self.assertEqual(page.number, 1)
     self.assertEqual(page.object_list.query.low_mark, 0)
     self.assertEqual(page.object_list.query.high_mark, 10)
     # Empty page
     page = helpers.get_page_from_search(self.orm_query_set, {"page": "11"})
     self.assertEqual(page.paginator.num_pages, 10)
     self.assertEqual(page.number, 10)
     self.assertEqual(page.object_list.query.low_mark, 90)
     self.assertEqual(page.object_list.query.high_mark, 100)
Esempio n. 3
0
 def test_get_page_from_search_orm_wrong_limit(self, mock_orm_count):
     for limit in self.WRONG_LIMITS:
         page = helpers.get_page_from_search(self.orm_query_set, {"limit": limit})
         self.assertEqual(page.paginator.num_pages, 10)
         self.assertEqual(page.number, 1)
         self.assertEqual(page.object_list.query.low_mark, 0)
         self.assertEqual(page.object_list.query.high_mark, 10)
Esempio n. 4
0
 def test_get_page_from_search_orm_with_params(self, mock_orm_count):
     page = helpers.get_page_from_search(
         self.orm_query_set, {"page": "2", "limit": "20"}
     )
     self.assertEqual(page.number, 2)
     self.assertEqual(page.object_list.query.low_mark, 20)
     self.assertEqual(page.object_list.query.high_mark, 40)
Esempio n. 5
0
 def test_get_page_from_search_orm_defaults(self, mock_orm_count):
     # ORM QuerySet
     page = helpers.get_page_from_search(self.orm_query_set, {})
     self.assertEqual(page.paginator.count, 100)
     self.assertEqual(page.paginator.num_pages, 10)
     self.assertEqual(page.number, 1)
     # The objects_list is the QuerySet SQL query
     self.assertEqual(page.object_list.query.low_mark, 0)
     self.assertEqual(page.object_list.query.high_mark, 10)
Esempio n. 6
0
 def test_get_page_from_search_es_defaults(self, mock_es_count):
     # Elasticsearch search
     page = helpers.get_page_from_search(self.es_search, {})
     # Count matches the return_value of the patch
     self.assertEqual(page.paginator.count, 100)
     # Default limit is 10 so there should be 10 pages
     self.assertEqual(page.paginator.num_pages, 10)
     # The first page is obtained
     self.assertEqual(page.number, 1)
     # The objects_list is the ES query, only with pagination
     self.assertEqual(page.object_list.to_dict(), {"from": 0, "size": 10})
Esempio n. 7
0
 def test_get_page_from_search_es_wrong_limit(self, mock_es_count):
     for limit in self.WRONG_LIMITS:
         page = helpers.get_page_from_search(self.es_search, {"limit": limit})
         self.assertEqual(page.paginator.num_pages, 10)
         self.assertEqual(page.number, 1)
         self.assertEqual(page.object_list.to_dict(), {"from": 0, "size": 10})
Esempio n. 8
0
 def test_get_page_from_search_es_with_params(self, mock_es_count):
     page = helpers.get_page_from_search(
         self.es_search, {"page": "2", "limit": "20"}
     )
     self.assertEqual(page.number, 2)
     self.assertEqual(page.object_list.to_dict(), {"from": 20, "size": 20})