def test_paginated_results(self, page_number, page_size, has_next): """ Test the page returned has the expected db objects and acts like a proper page object. """ id_range = get_object_range(page_number, page_size) db_objects = [build_mock_object(obj_id) for obj_id in id_range] self.mock_model.objects.filter = MagicMock(return_value=db_objects) page = paginate_search_results(self.mock_model, self.search_results, page_size, page_number) self.mock_model.objects.filter.assert_called_with(pk__in=id_range) self.assertEqual(db_objects, page.object_list) self.assertTrue(page.number, page_number) self.assertEqual(page.has_next(), has_next)
def test_invalid_page_number(self, page_num): """ Test that a Http404 error is raised with non-integer and out-of-range pages """ with self.assertRaises(Http404): paginate_search_results(self.mock_model, self.search_results, self.default_size, page_num)