Skip to content

Commit d03522b

Browse files
authored
Fix pagination (#119)
Ensure page parameter is actually passed to query parameters
1 parent 9ea77fb commit d03522b

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

changes/116.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix pagination

taiga/models/base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ def list(self, pagination=True, page_size=None, page=None, **queryparams): # no
6565
except (ValueError, TypeError):
6666
page_size = 100
6767
queryparams["page_size"] = page_size
68+
if page and pagination:
69+
queryparams["page"] = page
6870
result = self.requester.get(self.instance.endpoint, query=queryparams, paginate=pagination)
6971
objects = SearchableList()
7072
objects.extend(self.parse_list(result.json()))

tests/test_model_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,13 +245,13 @@ def test_call_model_base_list_elements_single_page(self, mock_requestmaker_get):
245245
mock_requestmaker_get.return_value = MockResponse(200, data)
246246
f_list = fakes.list(page_size=5, page=1)
247247
self.assertEqual(len(f_list), 5)
248-
mock_requestmaker_get.assert_called_with("fakes", query={"page_size": 5}, paginate=True)
248+
mock_requestmaker_get.assert_called_with("fakes", query={"page_size": 5, "page": 1}, paginate=True)
249249

250250
data = json.dumps(js_list[5:])
251251
mock_requestmaker_get.return_value = MockResponse(200, data)
252252
f_list = fakes.list(page_size=5, page=2)
253253
self.assertEqual(len(f_list), 4)
254-
mock_requestmaker_get.assert_called_with("fakes", query={"page_size": 5}, paginate=True)
254+
mock_requestmaker_get.assert_called_with("fakes", query={"page_size": 5, "page": 2}, paginate=True)
255255

256256
def test_to_dict_method(self):
257257
rm = RequestMaker("/api/v1", "fakehost", "faketoken")

tests/test_user_stories.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,33 @@ def test_list_attachments(self, mock_requestmaker_get):
2121
UserStory(rm, id=1).list_attachments()
2222
mock_requestmaker_get.assert_called_with("userstories/attachments", query={"object_id": 1}, paginate=True)
2323

24+
@patch("taiga.requestmaker.RequestMaker.get")
25+
def test_list_userstories_page_2(self, mock_requestmaker_get):
26+
mock_requestmaker_get.return_value = MockResponse(
27+
200, create_mock_json("tests/resources/userstories_list_success.json")
28+
)
29+
api = TaigaAPI(token="f4k3")
30+
api.user_stories.list(page=1, page_size=2)
31+
mock_requestmaker_get.assert_called_with("userstories", query={"page_size": 2, "page": 1}, paginate=True)
32+
33+
@patch("taiga.requestmaker.RequestMaker.get")
34+
def test_list_userstories_page_1(self, mock_requestmaker_get):
35+
mock_requestmaker_get.return_value = MockResponse(
36+
200, create_mock_json("tests/resources/userstories_list_success.json")
37+
)
38+
api = TaigaAPI(token="f4k3")
39+
api.user_stories.list(page_size=2)
40+
mock_requestmaker_get.assert_called_with("userstories", query={"page_size": 2}, paginate=True)
41+
42+
@patch("taiga.requestmaker.RequestMaker.get")
43+
def test_list_userstories_no_pagination(self, mock_requestmaker_get):
44+
mock_requestmaker_get.return_value = MockResponse(
45+
200, create_mock_json("tests/resources/userstories_list_success.json")
46+
)
47+
api = TaigaAPI(token="f4k3")
48+
api.user_stories.list(pagination=False, page=2, page_size=3)
49+
mock_requestmaker_get.assert_called_with("userstories", query={}, paginate=False)
50+
2451
@patch("taiga.requestmaker.RequestMaker.get")
2552
def test_single_userstory_parsing(self, mock_requestmaker_get):
2653
mock_requestmaker_get.return_value = MockResponse(

0 commit comments

Comments
 (0)