Skip to content

Commit

Permalink
Fix pagination
Browse files Browse the repository at this point in the history
Ensure page parameter is actually passed to query parameters
  • Loading branch information
yakky committed Oct 23, 2021
1 parent f448eda commit 7d3a38b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions changes/116.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix pagination
2 changes: 2 additions & 0 deletions taiga/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ def list(self, pagination=True, page_size=None, page=None, **queryparams): # no
except (ValueError, TypeError):
page_size = 100
queryparams["page_size"] = page_size
if page and pagination:
queryparams["page"] = page
result = self.requester.get(self.instance.endpoint, query=queryparams, paginate=pagination)
objects = SearchableList()
objects.extend(self.parse_list(result.json()))
Expand Down
27 changes: 27 additions & 0 deletions tests/test_user_stories.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,33 @@ def test_list_attachments(self, mock_requestmaker_get):
UserStory(rm, id=1).list_attachments()
mock_requestmaker_get.assert_called_with("userstories/attachments", query={"object_id": 1}, paginate=True)

@patch("taiga.requestmaker.RequestMaker.get")
def test_list_userstories_page_2(self, mock_requestmaker_get):
mock_requestmaker_get.return_value = MockResponse(
200, create_mock_json("tests/resources/userstories_list_success.json")
)
api = TaigaAPI(token="f4k3")
api.user_stories.list(page=1, page_size=2)
mock_requestmaker_get.assert_called_with("userstories", query={"page_size": 2, "page": 1}, paginate=True)

@patch("taiga.requestmaker.RequestMaker.get")
def test_list_userstories_page_1(self, mock_requestmaker_get):
mock_requestmaker_get.return_value = MockResponse(
200, create_mock_json("tests/resources/userstories_list_success.json")
)
api = TaigaAPI(token="f4k3")
api.user_stories.list(page_size=2)
mock_requestmaker_get.assert_called_with("userstories", query={"page_size": 2}, paginate=True)

@patch("taiga.requestmaker.RequestMaker.get")
def test_list_userstories_no_pagination(self, mock_requestmaker_get):
mock_requestmaker_get.return_value = MockResponse(
200, create_mock_json("tests/resources/userstories_list_success.json")
)
api = TaigaAPI(token="f4k3")
api.user_stories.list(pagination=False, page=2, page_size=3)
mock_requestmaker_get.assert_called_with("userstories", query={}, paginate=False)

@patch("taiga.requestmaker.RequestMaker.get")
def test_single_userstory_parsing(self, mock_requestmaker_get):
mock_requestmaker_get.return_value = MockResponse(
Expand Down

0 comments on commit 7d3a38b

Please sign in to comment.