Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_response_is_last_page(c, res):
res.data['paging']['total'] = 20
res.data['paging']['limit'] = 10
res.data['paging']['offset'] = 10
response = PaginatedResponse(c, res)
assert response.has_next() is False
assert response.has_prev() is True
def test_response_is_first_page(c, res):
res.data['paging']['total'] = 100
res.data['paging']['offset'] = 0
response = PaginatedResponse(c, res)
assert response.has_next() is True
assert response.has_prev() is False
def test_response_has_next_prev(c, res):
response = PaginatedResponse(c, res)
assert response.has_next() is True
assert response.has_prev() is False
def test_paginated_response_is_iterable(c, res):
response = PaginatedResponse(c, res)
assert list(iter(response)) == res.data['results']
def test_response_next(c, res):
res.data['paging']['total'] = 100
response = PaginatedResponse(c, res)
expect(c, 'GET', '/v1/payments/search', params={'offset': 10})
response.next()
def test_paginated_response_paging(c, res):
res.data['paging']['total'] = 20
res.data['paging']['limit'] = 10
res.data['paging']['offset'] = 0
response = PaginatedResponse(c, res)
assert response.total == 20
assert response.limit == 10
assert response.offset == 0
def test_response_prev(c, res):
res.data['paging']['total'] = 100
res.data['paging']['offset'] = 20
response = PaginatedResponse(c, res)
expect(c, 'GET', '/v1/payments/search', params={'offset': 10})
response.prev()
def _request(self, method, url, **kwargs):
try:
res = self._session.request(method, url, **kwargs)
res.raise_for_status()
except (requests.ConnectionError, requests.HTTPError) as error:
self._handle_request_error(error)
try:
data = res.json()
if 'paging' in data:
return response.PaginatedResponse(self, res)
except ValueError:
pass
return response.Response(self, res)