Skip to content

Commit

Permalink
add backward compatibility for createmeta_issuetypes & createmeta_fie…
Browse files Browse the repository at this point in the history
…ldtypes (#1838)
  • Loading branch information
paminov authored Mar 25, 2024
1 parent e8104ea commit 4960d8f
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
80 changes: 80 additions & 0 deletions jira/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2076,6 +2076,86 @@ def _check_createmeta_issuetypes(self) -> None:
"Use 'createmeta' instead."
)

def createmeta_issuetypes(
self,
projectIdOrKey: str | int,
startAt: int = 0,
maxResults: int = 50,
) -> dict[str, Any]:
"""Get the issue types metadata for a given project, required to create issues.
.. deprecated:: 3.6.0
Use :func:`project_issue_types` instead.
This API was introduced in JIRA Server / DC 8.4 as a replacement for the more general purpose API 'createmeta'.
For details see: https://confluence.atlassian.com/jiracore/createmeta-rest-endpoint-to-be-removed-975040986.html
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]
"""
warnings.warn(
"'createmeta_issuetypes' is deprecated and will be removed in future releases."
"Use 'project_issue_types' instead.",
DeprecationWarning,
stacklevel=2,
)
self._check_createmeta_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,
) -> dict[str, Any]:
"""Get the field metadata for a given project and issue type, required to create issues.
.. deprecated:: 3.6.0
Use :func:`project_issue_fields` instead.
This API was introduced in JIRA Server / DC 8.4 as a replacement for the more general purpose API 'createmeta'.
For details see: https://confluence.atlassian.com/jiracore/createmeta-rest-endpoint-to-be-removed-975040986.html
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]
"""
warnings.warn(
"'createmeta_fieldtypes' is deprecated and will be removed in future releases."
"Use 'project_issue_fields' instead.",
DeprecationWarning,
stacklevel=2,
)
self._check_createmeta_issuetypes()
return self._get_json(
f"issue/createmeta/{projectIdOrKey}/issuetypes/{issueTypeId}",
params={
"startAt": startAt,
"maxResults": maxResults,
},
)

def createmeta(
self,
projectKeys: tuple[str, str] | str | None = None,
Expand Down
19 changes: 19 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,25 @@ def test_cookie_auth_retry():
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


@pytest.mark.parametrize(
"mock_client_method", ["mock_cloud_only_method", "mock_experimental_method"]
)
Expand Down

0 comments on commit 4960d8f

Please sign in to comment.