Files
claude-config/bin/do_epic/backend/test_fake.py
T

70 lines
3.0 KiB
Python

import pathlib
import sys
import unittest
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[2]))
from do_epic.backend.contract import EpicStoreContract
from failure import Failure
from plan_store import jira_epic
from do_epic.backend.fake import MemoryEpic
class MemoryEpicContract(EpicStoreContract, unittest.TestCase):
def new_store(self) -> MemoryEpic:
return MemoryEpic("ABC-12")
def assign(self, store: MemoryEpic, key: str, name: str) -> None: # type: ignore[override]
store.change(key, assignee=name)
def comments_on(self, store: MemoryEpic, key: str) -> list[str]: # type: ignore[override]
return store.comments.get(key, [])
def close(self, store: MemoryEpic, key: str, status: str) -> None: # type: ignore[override]
store.change(key, status=status, done=True)
def person_files(self, store: MemoryEpic, summary: str) -> str: # type: ignore[override]
key = self.filed(store, store.epic_key, summary)
store.change(key, by_loop=False)
return key
def score(self, store: MemoryEpic, key: str, scores: dict[str, object]) -> None: # type: ignore[override]
read = jira_epic.scores(key, scores)
assert not isinstance(read, Failure), read
store.change(key, scores=read.scores, moves=read.moves, exempt=read.exempt)
def block(self, store: MemoryEpic, key: str, blocker: str) -> None: # type: ignore[override]
store.change(key, blockers=(*next(issue for issue in store.issues if issue.key == key).blockers, blocker))
class Failing(unittest.TestCase):
def test_every_read_filing_label_comment_and_rank_fails_with_the_reason_given(self) -> None:
store = MemoryEpic("ABC-12", fails="Jira is down")
down = Failure("Jira is down")
self.assertEqual((store.read(), store.file("ABC-12", "Count the runs.", "", ()), store.add_label("ABC-100", "api"), store.comment("ABC-100", "Hello."), store.rank("ABC-100", "ABC-101")), (down,) * 5)
class Ranking(unittest.TestCase):
def test_refuses_to_rank_beside_an_issue_that_isnt_a_child_of_the_epic(self) -> None:
store = MemoryEpic("ABC-12")
child = store.file("ABC-12", "Count the runs.", "", ())
self.assertEqual(store.rank(str(child), "ZZZ-1"), Failure(f"ZZZ-1 is not one of the child issues of the epic ABC-12, so {child} is not ranked"))
class Finishing(unittest.TestCase):
def test_finishes_an_issue_to_the_status_done(self) -> None:
store = MemoryEpic("ABC-12")
key = store.file("ABC-12", "Count the runs.", "", ())
self.assertIsNone(store.finish_issue(str(key)))
self.assertEqual([(issue.status, issue.done) for issue in store.issues], [("Done", True)])
def test_refuses_to_finish_an_issue_outside_the_epic_saying_so(self) -> None:
self.assertEqual(MemoryEpic("ABC-12").finish_issue("ZZZ-1"), Failure("ZZZ-1 is not one of the child issues of the epic ABC-12, so it cannot be finished"))
def test_fails_to_finish_with_the_reason_given(self) -> None:
self.assertEqual(MemoryEpic("ABC-12", fails="Jira is down").finish_issue("ABC-100"), Failure("Jira is down"))
if __name__ == "__main__":
unittest.main()