Skip to content

Commit

Permalink
More interactor stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroanan committed Jun 1, 2014
1 parent d47002d commit 62b45a8
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 20 deletions.
14 changes: 8 additions & 6 deletions aquarius/Aquarius.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,23 @@ def main(self):
self.__output.main()

def search_books(self, search_term):
interactor = self.__interactor_factory.get_search_book_interactor(self.__persistence)
return interactor.execute(search_term)
i = self.__interactor_factory.get_search_book_interactor(self.__persistence)
return i.execute(search_term)

def list_books_by_first_letter(self, first_letter):
return self.__persistence.list_books_by_first_letter(first_letter)
i = self.__interactor_factory.get_list_books_by_first_letter_interactor(self.__persistence)
return i.execute(first_letter)

def get_book_details(self, book_id):
return self.__persistence.get_book_details(book_id)
i = self.__interactor_factory.get_book_details_interactor(self.__persistence)
return i.execute(book_id)

def get_book_type(self, format_code):
return self.__persistence.get_book_type(format_code)

def add_book(self, book):
interactor = self.__interactor_factory.get_add_book_interactor(self.__persistence)
interactor.execute(book)
i = self.__interactor_factory.get_add_book_interactor(self.__persistence)
i.execute(book)

def harvest_books(self):
if not self.is_harvesting:
Expand Down
3 changes: 3 additions & 0 deletions aquarius/InteractorFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ def get_list_books_by_first_letter_interactor(self, persistence):
raise NotImplementedError

def get_search_book_interactor(self, persistence):
raise NotImplementedError

def get_book_details_interactor(self, param):
raise NotImplementedError
6 changes: 5 additions & 1 deletion aquarius/interactors/BasicInteractorFactory.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from aquarius.InteractorFactory import InteractorFactory
from aquarius.interactors.AddBookInteractor import AddBookInteractor
from aquarius.interactors.GetBookDetailsInteractor import GetBookDetailsInteractor
from aquarius.interactors.ListBooksByFirstLetterInteractor import ListBooksByFirstLetterInteractor
from aquarius.interactors.SearchBookInteractor import SearchBookInteractor

Expand All @@ -13,4 +14,7 @@ def get_list_books_by_first_letter_interactor(self, persistence):
return ListBooksByFirstLetterInteractor(persistence)

def get_search_book_interactor(self, persistence):
return SearchBookInteractor(persistence)
return SearchBookInteractor(persistence)

def get_book_details_interactor(self, persistence):
return GetBookDetailsInteractor(persistence)
7 changes: 7 additions & 0 deletions aquarius/interactors/GetBookDetailsInteractor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class GetBookDetailsInteractor(object):

def __init__(self, persistence):
self.__persistence = persistence

def execute(self, param):
self.__persistence.get_book_details(param)
Binary file removed design/Add Book Use Case/Add book flowchart.dia
Binary file not shown.
23 changes: 19 additions & 4 deletions tests/TestAquarius.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from aquarius.InteractorFactory import InteractorFactory
from aquarius.bookharvesting.HardcodedHarvester import HardcodedHarvester
from aquarius.interactors.AddBookInteractor import AddBookInteractor
from aquarius.interactors.GetBookDetailsInteractor import GetBookDetailsInteractor
from aquarius.interactors.ListBooksByFirstLetterInteractor import ListBooksByFirstLetterInteractor
from aquarius.output.web.Web import Web
from aquarius.persistence.hardcodedpersistence.HardcodedPersistence import HardcodedPersistence

Expand All @@ -22,9 +24,14 @@ def setUp(self):
def setup_interactors(self):
self.__search_book_interactor = Mock(Interactor)
self.__add_book_interactor = Mock(AddBookInteractor)
self.__list_books_by_first_letter_interactor = Mock(ListBooksByFirstLetterInteractor)
self.__get_book_details_interactor = Mock(GetBookDetailsInteractor)
self.__interactor_factory = InteractorFactory()
self.__interactor_factory.get_search_book_interactor = Mock(return_value=self.__search_book_interactor)
self.__interactor_factory.get_add_book_interactor = Mock(return_value=self.__add_book_interactor)
self.__interactor_factory.get_list_books_by_first_letter_interactor = \
Mock(return_value=self.__list_books_by_first_letter_interactor)
self.__interactor_factory.get_book_details_interactor = Mock(return_value=self.__get_book_details_interactor)

def __setup_harvester_mock(self):
self.__harvester = harvester = HardcodedHarvester(self.__app, None)
Expand All @@ -47,13 +54,21 @@ def test_search_books_calls_interactor(self):
self.__app.search_books("")
self.assertTrue(self.__search_book_interactor.execute.called)

def test_list_books_by_first_letter_calls_persistence(self):
def test_list_books_by_first_letter_uses_interactor_factory(self):
self.__app.list_books_by_first_letter("b")
self.assertTrue(self.__persistence.list_books_by_first_letter.called)
self.assertTrue(self.__interactor_factory.get_list_books_by_first_letter_interactor.called)

def test_get_book_details_calls_persistence(self):
def test_list_books_by_first_letter_calls_interactor(self):
self.__app.list_books_by_first_letter("b")
self.assertTrue(self.__list_books_by_first_letter_interactor.execute.called)

def test_get_book_details_uses_interactor_factory(self):
self.__app.get_book_details(0)
self.assertTrue(self.__interactor_factory.get_book_details_interactor.called)

def test_get_book_details_calls_interactor(self):
self.__app.get_book_details(0)
self.assertTrue(self.__persistence.get_book_details.called)
self.assertTrue(self.__get_book_details_interactor.execute.called)

def test_get_book_type_calls_persistence(self):
self.__app.get_book_type("EPUB")
Expand Down
14 changes: 10 additions & 4 deletions tests/TestInteractorFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@
class TestInteractorFactory(unittest.TestCase):

def setUp(self):
self.__f = InteractorFactory()
self.__target = InteractorFactory()

def test_get_add_book_interactor(self):
self.assertRaises(NotImplementedError, self.__f.get_add_book_interactor, "persistence")
self.__assertNotImplemented(self.__target.get_add_book_interactor)

def test_get_list_books_by_first_letter_interactor(self):
self.assertRaises(NotImplementedError, self.__f.get_list_books_by_first_letter_interactor, "persistence")
self.__assertNotImplemented(self.__target.get_list_books_by_first_letter_interactor)

def test_get_search_book_interactor(self):
self.assertRaises(NotImplementedError, self.__f.get_search_book_interactor, "persistence")
self.__assertNotImplemented(self.__target.get_search_book_interactor)

def test_get_book_details_interactor(self):
self.__assertNotImplemented(self.__target.get_book_details_interactor)

def __assertNotImplemented(self, method):
self.assertRaises(NotImplementedError, method, "persistence")
14 changes: 9 additions & 5 deletions tests/interactors/TestBasicInteractorFactory.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest
from aquarius.InteractorFactory import InteractorFactory
from aquarius.interactors.BasicInteractorFactory import BasicInteractorFactory
from aquarius.interactors.GetBookDetailsInteractor import GetBookDetailsInteractor
from aquarius.interactors.SearchBookInteractor import SearchBookInteractor
from aquarius.interactors.AddBookInteractor import AddBookInteractor
from aquarius.interactors.ListBooksByFirstLetterInteractor import ListBooksByFirstLetterInteractor
Expand All @@ -9,16 +9,20 @@
class TestBasicInteractorFactory(unittest.TestCase):

def setUp(self):
self.__f = BasicInteractorFactory()
self.__target = BasicInteractorFactory()

def test_get_add_book_interactor(self):
i = self.__f.get_add_book_interactor("persistence")
i = self.__target.get_add_book_interactor("persistence")
self.assertIsInstance(i, AddBookInteractor)

def test_get_list_books_by_first_letter_interactor(self):
i = self.__f.get_list_books_by_first_letter_interactor("persistence")
i = self.__target.get_list_books_by_first_letter_interactor("persistence")
self.assertIsInstance(i, ListBooksByFirstLetterInteractor)

def test_get_search_book_interactor(self):
i = self.__f.get_search_book_interactor("persistence")
i = self.__target.get_search_book_interactor("persistence")
self.assertIsInstance(i, SearchBookInteractor)

def test_get_get_book_details_interactor(self):
i = self.__target.get_book_details_interactor("persistence")
self.assertIsInstance(i, GetBookDetailsInteractor)
14 changes: 14 additions & 0 deletions tests/interactors/TestGetBookDetailsInteractor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import unittest
from unittest.mock import Mock
from aquarius.interactors.GetBookDetailsInteractor import GetBookDetailsInteractor
from aquarius.persistence.sqlitepersistence import SqlitePersistence


class TestGetBookDetailsInteractor(unittest.TestCase):

def test_execute_calls_persistence(self):
persistence = Mock(SqlitePersistence)
persistence.get_book_details = Mock()
target = GetBookDetailsInteractor(persistence)
target.execute("book_id")
self.assertTrue(persistence.get_book_details.called)

0 comments on commit 62b45a8

Please sign in to comment.