Skip to content

Commit

Permalink
Merge pull request #11 from davidjnevin/use_case_get_all_functionality
Browse files Browse the repository at this point in the history
Use case get all functionality
  • Loading branch information
davidjnevin authored Jan 28, 2024
2 parents bc60dda + c63254f commit 6455d30
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/chatcleaner/adapters/use_cases/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def __init__(
self.uow = uow
self.service = service

def _add(self, chat: str):
def _clean(self, chat: str):
with self.uow:
# clean
result = self.service.clean(chat)
Expand All @@ -26,3 +26,7 @@ def _add(self, chat: str):
model = cleaning_factory(**data_)
self.uow.cleaning.add(model)
self.uow.commit()

def _get_all(self):
with self.uow:
return self.uow.cleaning.get_all()
13 changes: 10 additions & 3 deletions src/chatcleaner/domain/ports/use_cases/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@ class CleanUseCaseInterface(abc.ABC):
def __init__(self, uow: CleaningUnitOfWorkInterface, chat: ChatServiceInterface):
raise NotImplementedError

def add(self, chat: str) -> None:
return self._add(chat)
def clean(self, chat: str) -> None:
return self._clean(chat)

def get_all(self):
return self._get_all()

@abc.abstractmethod
def _clean(self, chat: str) -> None:
raise NotImplementedError

@abc.abstractmethod
def _add(self, chat: str) -> None:
def _get_all(self):
raise NotImplementedError
25 changes: 23 additions & 2 deletions tests/integrations/test_cleaning_use_case.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
from chatcleaner.configurator.containers import Container


def test_clean_use_case_add(get_fake_container, get_clean_use_case):
def test_clean_use_case_clean(get_fake_container, get_clean_use_case):
with Container.cleaning_uow.override(get_fake_container.cleaning_uow):
with Container.chat_service.override(get_fake_container.chat_service):
get_clean_use_case.add("\n19:10:00 from David to Everyone:\ntest")
get_clean_use_case.clean("\n19:10:00 from David to Everyone:\ntest")
uow_ = get_fake_container.cleaning_uow()
with uow_:
result = uow_.cleaning.get_all()
assert len(result) == 1
assert result[0].chat == "\n19:10:00 from David to Everyone:\ntest"
assert result[0].cleaned_chat == "test"


def test_clean_use_case_get_all(get_fake_container, get_clean_use_case):
with Container.cleaning_uow.override(get_fake_container.cleaning_uow):
with Container.chat_service.override(get_fake_container.chat_service):
get_clean_use_case.clean("\n19:10:00 from David to Everyone:\ntest 1")
get_clean_use_case.clean("\n19:10:00 from David to Everyone:\ntest 2")
get_clean_use_case.clean("\n19:10:00 from David to Everyone:\ntest 3")
uow_ = get_fake_container.cleaning_uow()
with uow_:
result = get_clean_use_case.get_all()
# fixtures are scopes to module, so this should be 4
assert len(result) == 4
assert result[0].chat == "\n19:10:00 from David to Everyone:\ntest"
assert result[0].cleaned_chat == "test"
assert result[1].chat == "\n19:10:00 from David to Everyone:\ntest 1"
assert result[1].cleaned_chat == "test 1"
assert result[2].chat == "\n19:10:00 from David to Everyone:\ntest 2"
assert result[2].cleaned_chat == "test 2"
assert result[3].chat == "\n19:10:00 from David to Everyone:\ntest 3"
assert result[3].cleaned_chat == "test 3"

0 comments on commit 6455d30

Please sign in to comment.