Skip to content

Commit

Permalink
Add expand to JIRA.project and JIRA.projects (#865)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshheinrichs authored May 25, 2021
1 parent 07f246a commit eb80088
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
17 changes: 13 additions & 4 deletions jira/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2401,30 +2401,39 @@ def priority(self, id: str) -> Priority:

# Projects

def projects(self) -> List[Project]:
def projects(self, expand: Optional[str] = None) -> List[Project]:
"""Get a list of project Resources from the server visible to the current authenticated user.
Args:
expand (Optional[str]): extra information to fetch for each project
such as projectKeys and description.
Returns:
List[Project]
"""
r_json = self._get_json("project")
params = {}
if expand is not None:
params["expand"] = expand
r_json = self._get_json("project", params=params)
projects = [
Project(self._options, self._session, raw_project_json)
for raw_project_json in r_json
]
return projects

def project(self, id: str) -> Project:
def project(self, id: str, expand: Optional[str] = None) -> Project:
"""Get a project Resource from the server.
Args:
id (str): ID or key of the project to get
expand (Optional[str]): extra information to fetch for the project
such as projectKeys and description.
Returns:
Project
"""
return self._find_for_resource(Project, id)
return self._find_for_resource(Project, id, expand=expand)

# non-resource
@translate_resource_args
Expand Down
14 changes: 14 additions & 0 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1549,10 +1549,24 @@ def test_projects(self):
projects = self.jira.projects()
self.assertGreaterEqual(len(projects), 2)

def test_projects_expand(self):
projects = self.jira.projects()
for project in projects:
self.assertFalse(hasattr(project, "projectKeys"))
projects = self.jira.projects(expand="projectKeys")
for project in projects:
self.assertTrue(hasattr(project, "projectKeys"))

def test_project(self):
project = self.jira.project(self.project_b)
self.assertEqual(project.key, self.project_b)

def test_project_expand(self):
project = self.jira.project(self.project_b)
self.assertFalse(hasattr(project, "projectKeys"))
project = self.jira.project(self.project_b, expand="projectKeys")
self.assertTrue(hasattr(project, "projectKeys"))

# I have no idea what avatars['custom'] is and I get different results every time
# def test_project_avatars(self):
# avatars = self.jira.project_avatars(self.project_b)
Expand Down

0 comments on commit eb80088

Please sign in to comment.