Skip to content
Snippets Groups Projects
Commit 2c0f2b89 authored by Erwan Rouchet's avatar Erwan Rouchet Committed by Bastien Abadie
Browse files

Handle zero results in pagination

parent 02cc3e83
No related branches found
No related tags found
Loading
Pipeline #28149 passed
......@@ -48,6 +48,11 @@ class ResponsePaginator(Sized, Iterator):
if self.data and self.data.get('next') is None:
raise StopIteration
self._fetch_page(self.current_page + 1)
# Even after fetching a new page, if the new page is empty, just fail
if len(self.results) < 1:
raise StopIteration
return self.results.pop(0)
def __len__(self):
......
import pytest
import responses
from arkindex import ArkindexClient
@responses.activate
def test_pagination_empty():
responses.add(
responses.GET,
'https://dummy.test/api/v1/elements/',
json={'count': 0, 'previous': None, 'next': None, 'results': []},
)
cli = ArkindexClient('t0k3n', base_url='https://dummy.test')
with pytest.raises(StopIteration):
next(cli.paginate('ListElements'))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment