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 expand to JIRA.project and JIRA.projects #865

Merged
merged 1 commit into from
May 25, 2021
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
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 @@ -1548,10 +1548,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