Пример #1
0
class BookFactory(object):
    def __init__(self):
        self.__epubcreator = EpubCreator()
        self.__pdfcreator = PdfCreator()

    @property
    def epub_creator(self):
        return self.__epubcreator

    @epub_creator.setter
    def epub_creator(self, val):
        self.__epubcreator = val

    @property
    def pdf_creator(self):
        return self.__pdfcreator

    @pdf_creator.setter
    def pdf_creator(self, val):
        self.__pdfcreator = val

    def get_book(self, filepath):
        b = None
        if filepath.lower().endswith(".epub"):
            b = self.__epubcreator.create(filepath)
        elif filepath.lower().endswith("pdf"):
            b = self.__pdfcreator.create(filepath)
        return b
Пример #2
0
class TestEpubCreator(unittest.TestCase):

    def setUp(self):
        self.__epubPath = "tests/data/TreasureIsland.epub"
        self.__epc = EpubCreator()

    def test_get_epub_gets_correct_format_name(self):
        b = self.__getTreasureIsland()
        self.assertEquals("EPUB", b.formats[0].Format)

    def test_get_epub_gets_correct_location(self):
        b = self.__getTreasureIsland()
        self.assertEquals(self.__epubPath, b.formats[0].Location)

    def test_get_invalid_epub_returns_none(self):
        b = self.__epc.create("tests/data/NotAValidEpub.epub")
        self.assertIsNone(b)

    def __getTreasureIsland(self):
        return self.__epc.create(self.__epubPath)
Пример #3
0
 def __init__(self):
     self.__epubcreator = EpubCreator()
     self.__pdfcreator = PdfCreator()
Пример #4
0
 def test_get_epub_calls_epub_creator(self):
     epub_creator = EpubCreator()
     epub_creator.create = Mock()
     self.__f.epub_creator = epub_creator
     self.__f.get_book(self.__epubPath)
     self.assertTrue(epub_creator.create.called)
Пример #5
0
 def setUp(self):
     self.__epubPath = "tests/data/TreasureIsland.epub"
     self.__epc = EpubCreator()