diff --git a/src/examples/issue_classification_user_journey/issue_dispatcher/issue_dispatcher.py b/src/examples/issue_classification_user_journey/issue_dispatcher/issue_dispatcher.py index fa03a5c35..1d1bee37b 100644 --- a/src/examples/issue_classification_user_journey/issue_dispatcher/issue_dispatcher.py +++ b/src/examples/issue_classification_user_journey/issue_dispatcher/issue_dispatcher.py @@ -6,12 +6,12 @@ def __init__(self, id: str, title: str): self.title = title class IssuePort(ABC): - def get_next(self) -> Issue: + def new_issues(self) -> list[Issue]: pass def dispatch_to(self, recipient: str, issue_id: str) -> None: pass - - + def wait_for_notification(self): + pass class ClassifierPort(ABC): def classify(self, issue: Issue)->str: @@ -19,18 +19,22 @@ def classify(self, issue: Issue)->str: class IssueDispatcher(): - def __init__(self, issues: IssuePort, classifier: ClassifierPort): - self.issues = issues + def __init__(self, issue_port: IssuePort, classifier: ClassifierPort): + self.issue_port = issue_port self.classifier = classifier - def dispatch_next_issue(self): - issue = self.issues.get_next() - recipient = self.classifier.classify(issue) - self.issues.dispatch_to(recipient, issue.id) + def dispatch_issues(self): + issues = self.issue_port.new_issues() + for issue in issues: + recipient = self.classifier.classify(issue) + self.issue_port.dispatch_to(recipient, issue.id) def run(self): while True: - self.dispatch_next_issue() + self.issue_port.wait_for_notification() + self.dispatch_issues() + + diff --git a/src/examples/issue_classification_user_journey/test/test_issue_dispatching.py b/src/examples/issue_classification_user_journey/test/test_issue_dispatching.py index d763ad6b3..90afd191a 100644 --- a/src/examples/issue_classification_user_journey/test/test_issue_dispatching.py +++ b/src/examples/issue_classification_user_journey/test/test_issue_dispatching.py @@ -1,4 +1,5 @@ +from time import sleep from typing import Sequence from examples.issue_classification_user_journey.issue_dispatcher.issue_dispatcher import ClassifierPort, Issue, IssueDispatcher, IssuePort @@ -9,11 +10,15 @@ def __init__(self, issues: Sequence[tuple[str, str]]): self.issues = [Issue(id=issue[1], title=issue[0]) for issue in issues] self.dispatched_issues = {} - def get_next(self) -> Issue: + def new_issues(self) -> list[Issue]: return self.issues[0] def dispatch_to(self, recipient: str, issue_id: str) -> None: self.dispatched_issues[issue_id] = recipient + + def wait_for_notification(self): + sleep(1) + class AlwaysSameClass(ClassifierPort): def __init__(self, label: str): self.label = label @@ -21,14 +26,13 @@ def __init__(self, label: str): def classify(self, _issue: Issue) -> str: return self.label - def test_should_dispatch_new_issue() -> None: # Given new issues issue_stub = IssueAdapterFake([("My Computer does not work.", "1")]) classifier_stub = AlwaysSameClass(label="IT") # When issue_dispatcher = IssueDispatcher(issue_stub, classifier_stub) - issue_dispatcher.dispatch_next_issue() + issue_dispatcher.dispatch_issues() # Then assert issue_stub.dispatched_issues["1"] == "IT"