Skip to content

Commit

Permalink
Add expand to JIRA.project and JIRA.projects
Browse files Browse the repository at this point in the history
  • Loading branch information
joshheinrichs committed May 24, 2021
1 parent 7d229f4 commit 29f09c4
Show file tree
Hide file tree
Showing 2 changed files with 23 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
10 changes: 10 additions & 0 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1548,10 +1548,20 @@ def test_projects(self):
projects = self.jira.projects()
self.assertGreaterEqual(len(projects), 2)

def test_projects_expand(self):
project = self.jira.projects(expand='description')[0]
self.assertTrue(hasattr(project, 'description'))
self.assertFalse(hasattr(project, 'lead'))

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, expand='description')
self.assertTrue(hasattr(project, 'description'))
self.assertFalse(hasattr(project, 'lead'))

# 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 29f09c4

Please sign in to comment.