コード例 #1
0
 def __init__(self, app):
     self.__app = app
     self.__search_handler = HtmlRequestHandlerSearch(self.__app)
     self.__book_handler = HtmlRequestHandlerBook(self.__app)
     self.__first_letter_handler = HtmlRequestHandlerFirstLetter(self.__app)
     self.__index_handler = HtmlRequestHandlerIndex(self.__app)
     self.__download_handler = HtmlRequestHandlerDownload(self.__app)
コード例 #2
0
class HtmlRequestHandler(object):

    def __init__(self, app):
        self.__app = app
        self.__search_handler = HtmlRequestHandlerSearch(self.__app)
        self.__book_handler = HtmlRequestHandlerBook(self.__app)
        self.__first_letter_handler = HtmlRequestHandlerFirstLetter(self.__app)
        self.__index_handler = HtmlRequestHandlerIndex(self.__app)
        self.__download_handler = HtmlRequestHandlerDownload(self.__app)

    def index_handler(self):
        return self.__index_handler.handle()
    
    def search_handler(self, search_term):
        return self.__search_handler.handle(search_term)
        
    def harvest_handler(self):
        self.__app.harvest_books()
        return self.index_handler()
        
    def book_handler(self, book_id):
        return self.__book_handler.handle(book_id)
    
    def download_handler(self, book_id, format_code):
        self.__download_handler.handle(book_id, format_code)
    
    def first_letter_handler(self, first_letter):
        return self.__first_letter_handler.handle(first_letter)

    def set_search_handler(self, handler):
        self.__search_handler = handler

    def set_book_handler(self, handler):
        self.__book_handler = handler

    def set_first_letter_handler(self, handler):
        self.__first_letter_handler = handler

    def set_index_handler(self, handler):
        self.__index_handler = handler

    def set_download_handler(self, download_handler):
        self.__download_handler = download_handler
コード例 #3
0
class TestHtmlRequestHandlerFirstLetter(RequestHandlerTestBase):
    def setUp(self):
        self.initialise_app_mock()
        self.initialise_mock_search_template_handler()
        self.__h = HtmlRequestHandlerFirstLetter(self.app)
        self.__h.set_search_template_handler(self.__search_template_handler)

    def initialise_app_mock(self):
        RequestHandlerTestBase.initialise_app_mock(self)
        self.app.list_books_by_first_letter = Mock(return_value=[])

    def initialise_mock_search_template_handler(self):
        self.__search_template_handler = SearchTemplateHandler()
        self.__search_template_handler.render_search_template = Mock(return_value=None)

    def test_first_letter_handler_calls_application(self):
        self.__h.handle("t")
        self.assert_called(self.app.list_books_by_first_letter)

    def test_first_letter_handler_calls_search_template_handler(self):
        self.__h.handle("t")
        self.assert_called(self.__search_template_handler.render_search_template)
コード例 #4
0
 def setUp(self):
     self.initialise_app_mock()
     self.initialise_mock_search_template_handler()
     self.__h = HtmlRequestHandlerFirstLetter(self.app)
     self.__h.set_search_template_handler(self.__search_template_handler)