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

improve explanation of exception when two sprints with the same name are found #1405

Merged
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
22 changes: 19 additions & 3 deletions jira/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4516,13 +4516,29 @@ def sprints(
self.AGILE_BASE_URL,
)

def sprints_by_name(self, id, extended=False):
def sprints_by_name(
self, id: Union[str, int], extended: bool = False, state: str = None
) -> Dict[str, Dict[str, Any]]:
"""Get a dictionary of sprint Resources where the name of the sprint is the key.

Args:
board_id (int): the board to get sprints from
extended (bool): Deprecated.
state (str): Filters results to sprints in specified states. Valid values: `future`, `active`, `closed`.
You can define multiple states separated by commas
Comment on lines +4527 to +4528
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this case sensitive?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no clue didnt validate this just copied from sprints()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

beyond this PR then


Returns:
Dict[str, Dict[str, Any]]: dictionary of sprints with the sprint name as key
"""
sprints = {}
for s in self.sprints(id, extended=extended):
for s in self.sprints(id, extended=extended, state=state):
if s.name not in sprints:
sprints[s.name] = s.raw
else:
raise Exception
raise JIRAError(
f"There are multiple sprints defined with the name {s.name} on board id {id},\n"
f"returning a dict with sprint names as a key, assumes unique names for each sprint"
)
return sprints

def update_sprint(self, id, name=None, startDate=None, endDate=None, state=None):
Expand Down
17 changes: 14 additions & 3 deletions tests/resources/test_sprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
from functools import lru_cache
from typing import Iterator, Tuple

import pytest as pytest

from jira.exceptions import JIRAError
from jira.resources import Board, Filter, Sprint
from tests.conftest import JiraTestCase, rndstr

Expand All @@ -14,9 +17,9 @@ def setUp(self):
self.issue_3 = self.test_manager.project_b_issue3

uniq = rndstr()
self.board_name = "board-" + uniq
self.sprint_name = "sprint-" + uniq
self.filter_name = "filter-" + uniq
self.board_name = f"board-{uniq}"
self.sprint_name = f"sprint-{uniq}"
self.filter_name = f"filter-{uniq}"

self.board, self.filter = self._create_board_and_filter()

Expand Down Expand Up @@ -97,3 +100,11 @@ def test_move_issue_to_backlog(self):
# THEN: There is no longer the sprint assigned
updated_issue_1 = self.jira.issue(self.issue_1)
assert updated_issue_1.get_field(self._sprint_customfield()) is None

def test_two_sprints_with_the_same_name_raise_a_jira_error_when_sprints_by_name_is_called(
self,
):
with self._create_sprint():
with self._create_sprint():
with pytest.raises(JIRAError):
self.jira.sprints_by_name(self.board.id)