Re-rank Jira's backlog to match an epic's ranking, moving only the issues the loop filed
This commit is contained in:
@@ -6,7 +6,8 @@ import unittest
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from do_epic.ranking import chain, EpicItem, ranked, RepoRanking
|
||||
from do_epic.backend.fake import MemoryEpic
|
||||
from do_epic.ranking import chain, EpicItem, ranked, reranked, RepoRanking
|
||||
from failure import Failure
|
||||
from plan.todo_table import Item, parse_moves
|
||||
|
||||
@@ -155,5 +156,91 @@ class RankedTest(unittest.TestCase):
|
||||
self.assertIsInstance(order([item(1, "epic 1 by 9")], {"billing-api": VOIDED}, "V +"), Failure)
|
||||
|
||||
|
||||
class Recording(MemoryEpic):
|
||||
"""A MemoryEpic that keeps each rank asked of it, and refuses the one to rank the issue named in refused."""
|
||||
refused: str | None = None
|
||||
asked: list[tuple[str, str, bool]]
|
||||
|
||||
def rank(self, key: str, other: str, after: bool = False) -> None | Failure:
|
||||
self.asked.append((key, other, after))
|
||||
return Failure("Jira answered 403") if key == self.refused else super().rank(key, other, after)
|
||||
|
||||
|
||||
def epic(*people: int, issues: int = 4) -> Recording:
|
||||
"""An epic of child issues ABC-100 onwards, the loop's apart from those whose places are in people."""
|
||||
store = Recording("ABC-12")
|
||||
store.asked = []
|
||||
for place in range(issues):
|
||||
store.file("ABC-12", f"Item {place}.", "", ())
|
||||
if place in people:
|
||||
store.change(f"ABC-{100 + place}", by_loop=False)
|
||||
return store
|
||||
|
||||
|
||||
def keys(store: MemoryEpic) -> list[str]:
|
||||
read = store.read()
|
||||
assert isinstance(read, list), read
|
||||
return [issue.key for issue in read]
|
||||
|
||||
|
||||
class RerankedTest(unittest.TestCase):
|
||||
def test_the_loops_issues_take_their_slots_in_the_order_given_and_a_persons_keep_theirs(self) -> None:
|
||||
store = epic(1)
|
||||
self.assertEqual(reranked(store, ["ABC-103", "ABC-100", "ABC-102"]), None)
|
||||
self.assertEqual(keys(store), ["ABC-103", "ABC-101", "ABC-100", "ABC-102"])
|
||||
|
||||
def test_the_last_slot_takes_its_issue_where_a_persons_issue_comes_before_it(self) -> None:
|
||||
store = epic(0, issues=3)
|
||||
self.assertEqual(reranked(store, ["ABC-102", "ABC-101"]), None)
|
||||
self.assertEqual(keys(store), ["ABC-100", "ABC-102", "ABC-101"])
|
||||
|
||||
def test_an_order_the_backlog_already_reads_in_ranks_nothing(self) -> None:
|
||||
store = epic(1)
|
||||
self.assertEqual(reranked(store, ["ABC-100", "ABC-102", "ABC-103"]), None)
|
||||
self.assertEqual(store.asked, [])
|
||||
|
||||
def test_ranks_only_the_issues_out_of_place(self) -> None:
|
||||
store = epic(issues=5)
|
||||
self.assertEqual(reranked(store, ["ABC-100", "ABC-101", "ABC-102", "ABC-104", "ABC-103"]), None)
|
||||
self.assertEqual(store.asked, [("ABC-103", "ABC-104", True)])
|
||||
|
||||
def test_an_issue_the_order_doesnt_name_keeps_its_slot(self) -> None:
|
||||
store = epic()
|
||||
store.change("ABC-101", status="Done", done=True)
|
||||
self.assertEqual(reranked(store, ["ABC-103", "ABC-102", "ABC-100"]), None)
|
||||
self.assertEqual(keys(store), ["ABC-103", "ABC-101", "ABC-102", "ABC-100"])
|
||||
|
||||
def test_sub_tasks_hold_no_slot_and_follow_their_parent(self) -> None:
|
||||
store = epic(issues=2)
|
||||
task = store.file("ABC-100", "A task.", "", ())
|
||||
self.assertEqual(reranked(store, ["ABC-101", "ABC-100"]), None)
|
||||
self.assertEqual(keys(store), ["ABC-101", "ABC-100", task])
|
||||
|
||||
def test_refuses_an_order_naming_a_persons_issue_a_sub_task_an_issue_outside_the_epic_or_one_twice(self) -> None:
|
||||
store = epic(1)
|
||||
task = store.file("ABC-100", "A task.", "", ())
|
||||
for order, reason in (
|
||||
(["ABC-101", "ABC-100"], "ABC-101 is not one of the child issues of the epic ABC-12 that the loop filed, so the backlog was not re-ranked"),
|
||||
([task, "ABC-100"], f"{task} is not one of the child issues of the epic ABC-12 that the loop filed, so the backlog was not re-ranked"),
|
||||
(["ZZZ-1"], "ZZZ-1 is not one of the child issues of the epic ABC-12 that the loop filed, so the backlog was not re-ranked"),
|
||||
(["ABC-100", "ABC-102", "ABC-100"], "the order names ABC-100 twice, so the backlog was not re-ranked"),
|
||||
):
|
||||
with self.subTest(order=order):
|
||||
self.assertEqual(reranked(store, order), Failure(reason))
|
||||
self.assertEqual(store.asked, [])
|
||||
|
||||
def test_a_rank_the_tracker_refuses_stops_the_walk_and_names_the_order_to_finish_by_hand(self) -> None:
|
||||
store = epic()
|
||||
store.refused = "ABC-101"
|
||||
self.assertEqual(reranked(store, ["ABC-103", "ABC-102", "ABC-101", "ABC-100"]), Failure("cannot rank ABC-101 just before ABC-100: Jira answered 403; the re-rank stopped there, so rank the loop's issues in ABC-12's backlog by hand as ABC-103, ABC-102, ABC-101, ABC-100"))
|
||||
self.assertEqual(store.asked, [("ABC-100", "ABC-103", True), ("ABC-101", "ABC-100", False)])
|
||||
|
||||
def test_a_read_that_fails_ranks_nothing(self) -> None:
|
||||
store = epic()
|
||||
store.fails = "Jira is down"
|
||||
self.assertEqual(reranked(store, ["ABC-101"]), Failure("Jira is down"))
|
||||
self.assertEqual(store.asked, [])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user