Beispiel #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
Beispiel #2
0
class TestPdfCreator(unittest.TestCase):

    def setUp(self):
        self.__path = "tests/data/1.pdf"
        self.__p = PdfCreator()

    def test_create_with_invalid_path_gives_none(self):
        self.assertIsNone(self.__p.create("/tmp/1.pdf"))

    def test_create_with_valid_path_gives_a_book(self):
        self.assertIsInstance(self.__p.create(self.__path), Book)

    def testCallingCreateGivesCorrectBookFormat(self):
        b = self.__p.create(self.__path)
        self.assertEquals("PDF", b.formats[0].Format)

    def testCallingCreateGivesCorrectBookLocation(self):
        b = self.__p.create(self.__path)
        self.assertEquals(self.__path, b.formats[0].Location)
Beispiel #3
0
 def __init__(self):
     self.__epubcreator = EpubCreator()
     self.__pdfcreator = PdfCreator()
Beispiel #4
0
 def test_get_pdf_calls_pdf_creator(self):
     pdf_creator = PdfCreator()
     pdf_creator.create = Mock()
     self.__f.pdf_creator = pdf_creator
     self.__f.get_book(self.__pdfpath)
     self.assertTrue(pdf_creator.create.called)
Beispiel #5
0
 def setUp(self):
     self.__path = "tests/data/1.pdf"
     self.__p = PdfCreator()