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

support pagination in createmeta methods #1729

Merged
merged 6 commits into from
Dec 23, 2023
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
26 changes: 24 additions & 2 deletions jira/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1735,6 +1735,8 @@ def create_customer_request(
def createmeta_issuetypes(
self,
projectIdOrKey: str | int,
startAt: int = 0,
maxResults: int = 50,
paminov marked this conversation as resolved.
Show resolved Hide resolved
) -> dict[str, Any]:
"""Get the issue types metadata for a given project, required to create issues.

Expand All @@ -1743,6 +1745,10 @@ def createmeta_issuetypes(

Args:
projectIdOrKey (Union[str, int]): id or key of the project for which to get the metadata.
startAt (int): Index of the first issue to return. (Default: ``0``)
maxResults (int): Maximum number of issues to return.
Total number of results is available in the ``total`` attribute of the returned :class:`ResultList`.
If maxResults evaluates to False, it will try to get all issues in batches. (Default: ``50``)

Returns:
Dict[str, Any]
Expand All @@ -1753,12 +1759,20 @@ def createmeta_issuetypes(
"Use 'createmeta' instead."
)

return self._get_json(f"issue/createmeta/{projectIdOrKey}/issuetypes")
return self._get_json(
f"issue/createmeta/{projectIdOrKey}/issuetypes",
params={
"startAt": startAt,
"maxResults": maxResults,
},
)

def createmeta_fieldtypes(
self,
projectIdOrKey: str | int,
issueTypeId: str | int,
startAt: int = 0,
maxResults: int = 50,
paminov marked this conversation as resolved.
Show resolved Hide resolved
) -> dict[str, Any]:
"""Get the field metadata for a given project and issue type, required to create issues.

Expand All @@ -1768,6 +1782,10 @@ def createmeta_fieldtypes(
Args:
projectIdOrKey (Union[str, int]): id or key of the project for which to get the metadata.
issueTypeId (Union[str, int]): id of the issue type for which to get the metadata.
startAt (int): Index of the first issue to return. (Default: ``0``)
maxResults (int): Maximum number of issues to return.
Total number of results is available in the ``total`` attribute of the returned :class:`ResultList`.
If maxResults evaluates to False, it will try to get all issues in batches. (Default: ``50``)

Returns:
Dict[str, Any]
Expand All @@ -1779,7 +1797,11 @@ def createmeta_fieldtypes(
)

return self._get_json(
f"issue/createmeta/{projectIdOrKey}/issuetypes/{issueTypeId}"
f"issue/createmeta/{projectIdOrKey}/issuetypes/{issueTypeId}",
params={
"startAt": startAt,
"maxResults": maxResults,
},
)

def createmeta(
Expand Down
19 changes: 19 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,22 @@ def test_cookie_auth_retry():
)
# THEN: We don't get a RecursionError and only call the reset_function once
mock_reset_func.assert_called_once()


def test_createmeta_issuetypes_pagination(cl_normal, slug):
"""Test createmeta_issuetypes pagination kwargs"""
issue_types_resp = cl_normal.createmeta_issuetypes(slug, startAt=50, maxResults=100)
assert issue_types_resp["startAt"] == 50
assert issue_types_resp["maxResults"] == 100


def test_createmeta_fieldtypes_pagination(cl_normal, slug):
"""Test createmeta_fieldtypes pagination kwargs"""
issue_types = cl_normal.createmeta_issuetypes(slug)
assert issue_types["total"]
issue_type_id = issue_types["values"][-1]["id"]
field_types_resp = cl_normal.createmeta_fieldtypes(
projectIdOrKey=slug, issueTypeId=issue_type_id, startAt=50, maxResults=100
)
assert field_types_resp["startAt"] == 50
assert field_types_resp["maxResults"] == 100
Loading