Skip to content

Commit

Permalink
WIP: dispatches new issues
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianSchepersAA committed Apr 11, 2024
1 parent 96fc418 commit 4ab9d0e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,36 @@
from abc import ABC

class Issue():
def __init__(self, id: str, title: str):
self.id = id
self.title = title

class IssuePort(ABC):
pass
def get_next(self) -> Issue:
pass
def dispatch_to(self, recipient: str, issue_id: str) -> None:
pass


class IssueDispatcher():
def __init__(self, issue_port: IssuePort):

class ClassifierPort(ABC):
def classify(self, issue: Issue)->str:
pass


class IssueDispatcher():
def __init__(self, issues: IssuePort, classifier: ClassifierPort):
self.issues = issues
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 run(self):
while True:
self.dispatch_next_issue()



Original file line number Diff line number Diff line change
@@ -1,18 +1,37 @@

from typing import Sequence
from examples.issue_classification_user_journey.issue_dispatcher.issue_dispatcher import IssueDispatcher, IssuePort

from examples.issue_classification_user_journey.issue_dispatcher.issue_dispatcher import ClassifierPort, Issue, IssueDispatcher, IssuePort


class IssueAdapterFake(IssuePort):
def __init__(self, issues: Sequence[str]):
self.issues = issues
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:
return self.issues[0]

def dispatch_to(self, recipient: str, issue_id: str) -> None:
self.dispatched_issues[issue_id] = recipient
class AlwaysSameClass(ClassifierPort):
def __init__(self, label: str):
self.label = label

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."])
issue_stub = IssueAdapterFake([("My Computer does not work.", "1")])
classifier_stub = AlwaysSameClass(label="IT")
# When
issue_dispatcher = IssueDispatcher(issue_stub)
issue_dispatcher = IssueDispatcher(issue_stub, classifier_stub)
issue_dispatcher.dispatch_next_issue()
# Then
assert issue_stub.dispatched_issues["1"] == "IT"




Expand Down

0 comments on commit 4ab9d0e

Please sign in to comment.