Skip to content

Commit

Permalink
- Refactor to make Jira adapter driving
Browse files Browse the repository at this point in the history
- Start adding Jira adapter
TASK: IL-422
  • Loading branch information
FlorianSchepersAA committed Apr 12, 2024
1 parent 9df0f08 commit e1192f7
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
from .issue_dispatcher import IssueDispatcher
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,21 @@ def __init__(self, id: str, title: str):
self.id = id
self.title = title

class IssuePort(ABC):
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:
pass

class IssuePort(ABC):
def assign_issues(self, issues: list[Issue])->dict[str, str]:
pass

class IssueDispatcher():
def __init__(self, issue_port: IssuePort, classifier: ClassifierPort):
self.issue_port = issue_port
class IssueAssigner(IssuePort):
def __init__(self, classifier: ClassifierPort):
self.classifier = classifier

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.issue_port.wait_for_notification()
self.dispatch_issues()
def assign_issues(self, issues: list[Issue]) -> dict[str, str]:
return {issue.id: self.classifier.classify(issue) for issue in issues}




Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,5 @@
from examples.issue_classification_user_journey.issue_dispatcher.issue_dispatcher import ClassifierPort, Issue, IssueAssigner

from time import sleep
from typing import Sequence

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


class IssueAdapterFake(IssuePort):
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 new_issues(self) -> list[Issue]:
return self.issues

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
Expand All @@ -28,13 +9,13 @@ def classify(self, _issue: Issue) -> str:

def test_should_dispatch_new_issue() -> None:
# Given new issues
issue_stub = IssueAdapterFake([("My Computer does not work.", "1")])
issues = [Issue(id="1", title="My Computer does not work.")]
classifier_stub = AlwaysSameClass(label="IT")
# When
issue_dispatcher = IssueDispatcher(issue_stub, classifier_stub)
issue_dispatcher.dispatch_issues()
issue_assigner = IssueAssigner(classifier_stub)
assignements = issue_assigner.assign_issues(issues)
# Then
assert issue_stub.dispatched_issues["1"] == "IT"
assert assignements == {"1": "IT"}



Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from examples.issue_classification_user_journey.issue_dispatcher.issue_dispatcher import ClassifierPort, Issue, IssueAssigner


class AlwaysSameClass(ClassifierPort):
def __init__(self, label: str):
self.label = label

def classify(self, _issue: Issue) -> str:
return self.label


def test_should_send_new_issues_to_issue_assigner():
# Given
classifier_stub = AlwaysSameClass("IT")
issue_assigner = IssueAssigner(classifier_stub)
# When

0 comments on commit e1192f7

Please sign in to comment.