Skip to content
This repository was archived by the owner on Dec 16, 2025. It is now read-only.

Commit 25a27b8

Browse files
committed
Clean up fix and add actual test for page[number] computation
1 parent 92610a0 commit 25a27b8

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

flask_rest_jsonapi/pagination.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
"""Helper to create pagination links according to jsonapi specification"""
44

5+
from __future__ import division
56
from six.moves.urllib.parse import urlencode
67
from math import ceil
78
from copy import copy
@@ -29,7 +30,7 @@ def add_pagination_links(data, object_count, querystring, base_url):
2930
if querystring.pagination.get('size') != '0' and object_count > 1:
3031
# compute last link
3132
page_size = int(querystring.pagination.get('size', 0)) or current_app.config['PAGE_SIZE']
32-
last_page = int(ceil(1. * object_count / page_size))
33+
last_page = int(ceil(object_count / page_size))
3334

3435
if last_page > 1:
3536
links['first'] = links['last'] = base_url

tests/test_sqlalchemy_data_layer.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,11 @@ def __init__(self, kwargs):
330330

331331
def test_add_pagination_links(app):
332332
with app.app_context():
333-
qs = {'page[number]': '15', 'page[size]': '10'}
333+
qs = {'page[number]': '2', 'page[size]': '10'}
334334
qsm = QSManager(qs, None)
335-
add_pagination_links(dict(), 1000, qsm, str())
336-
335+
pagination_data = dict()
336+
add_pagination_links(pagination_data, 43, qsm, str())
337+
assert pagination_data['links']['last'] == '?page%5Bsize%5D=10&page%5Bnumber%5D=5'
337338

338339
def test_Node(person_model, person_schema, monkeypatch):
339340
from copy import deepcopy

0 commit comments

Comments
 (0)