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

Add projectstatuses method to get project statuses (missing endpoint) #1267

Merged
merged 9 commits into from
Feb 10, 2023
21 changes: 20 additions & 1 deletion jira/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2914,7 +2914,10 @@ def myself(self) -> Dict[str, Any]:
# Status

def statuses(self) -> List[Status]:
"""Get a list of status Resources from the server.
"""Get a list of all status Resources from the server.

Refer to :py:meth:`JIRA.issue_types_for_project` for getting statuses
for a specific issue type within a specific project.

Returns:
List[Status]
Expand All @@ -2926,6 +2929,22 @@ def statuses(self) -> List[Status]:
]
return statuses

def issue_types_for_project(self, projectIdOrKey: str) -> List[IssueType]:
"""Get a list of issue types available within the project.

Each project has a set of valid issue types and each issue type has a set of valid statuses.
The valid statuses for a given issue type can be extracted via: `issue_type_x.statuses`

Returns:
List[IssueType]
"""
r_json = self._get_json(f"project/{projectIdOrKey}/statuses")
issue_types = [
IssueType(self._options, self._session, raw_stat_json)
for raw_stat_json in r_json
]
return issue_types

def status(self, id: str) -> Status:
"""Get a status Resource from the server.

Expand Down
24 changes: 24 additions & 0 deletions tests/resources/test_project_statuses.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from tests.conftest import JiraTestCase


class ProjectStatusesByIssueTypeTests(JiraTestCase):
def test_issue_types_for_project(self):
issue_types = self.jira.issue_types_for_project(self.project_a)

# should have at least one issue type within the project
self.assertGreater(len(issue_types), 0)

# get unique statuses across all issue types
statuses = []
for issue_type in issue_types:
# should have at least one valid status within an issue type by endpoint documentation
self.assertGreater(len(issue_type.statuses), 0)
statuses.extend(issue_type.statuses)
unique_statuses = list(set(statuses))

# test status id and name for each status within the project
for status in unique_statuses:
self_status_id = self.jira.status(status.id).id
self.assertEqual(self_status_id, status.id)
self_status_name = self.jira.status(status.name).name
self.assertEqual(self_status_name, status.name)