Skip to content

Commit 9969438

Browse files
authored
Merge pull request #69 from jcampbell/last_page_fix
Avoid error from integer truncation in calculation of last_page (#67)
2 parents 5dee5b4 + 55d51d7 commit 9969438

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

flask_rest_jsonapi/pagination.py

Lines changed: 1 addition & 0 deletions
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

tests/test_sqlalchemy_data_layer.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22

3-
from six.moves.urllib.parse import urlencode
3+
from six.moves.urllib.parse import urlencode, parse_qs
44
import pytest
55

66
from sqlalchemy import create_engine, Column, Integer, DateTime, String, ForeignKey
@@ -330,10 +330,13 @@ 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_dict = dict()
336+
add_pagination_links(pagination_dict, 43, qsm, str())
337+
last_page_dict = parse_qs(pagination_dict['links']['last'][1:])
338+
assert len(last_page_dict['page[number]']) == 1
339+
assert last_page_dict['page[number]'][0] == '5'
337340

338341
def test_Node(person_model, person_schema, monkeypatch):
339342
from copy import deepcopy

0 commit comments

Comments
 (0)