Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

count deleted by total_records fixes 1170 #1630

Merged
merged 3 commits into from
May 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This document describes changes between each past release.
------------------

- Batch endpoint now checks for and aborts any parent request if subrequest encounters 409 constraint violation (fixes #1569)
- Fix a bug where you could not reach the last records via Next-Header when deleting with pagination (fixes #1170)

9.0.0 (2018-04-25)
------------------
Expand Down
3 changes: 1 addition & 2 deletions kinto/core/resource/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,7 @@ def collection_delete(self):
self._add_timestamp_header(self.request.response, timestamp=timestamp)

# Add pagination header
offset = offset + len(deleted)
if limit and len(deleted) == limit and offset < total_records:
if limit and len(deleted) == limit and total_records > 1:
next_page = self._next_page_url(sorting, limit, lastrecord, offset)
self.request.response.headers['Next-Page'] = next_page
else:
Expand Down
18 changes: 18 additions & 0 deletions tests/core/resource/test_pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,24 @@ def test_return_total_records_in_headers_matching_deletable(self):
count = headers['Total-Records']
self.assertEquals(int(count), 20)

def test_paginated_delete_second_to_last_gets_next_header(self):
self.resource.collection_get()
get_all_headers = self.last_response.headers
count = int(get_all_headers['Total-Records']) - 1

self.validated['querystring'] = {'_limit': 1}
headers = []
for i in range(count):
self.resource.collection_delete()
headers.append(self.last_response.headers)
self._setup_next_page()

self.resource.collection_delete()
headers.append(self.last_response.headers)

self.assertIn('Next-Page', headers[count - 1])
self.assertNotIn('Next-Page', headers[count])

def test_token_cannot_be_reused_twice(self):
self.resource.request.method = "DELETE"
self.validated['querystring']['_limit'] = 3
Expand Down