Example #1
0
    def test_make_pdf1(self):
        """
        Make pdf from previously downloaded images - simulated on copied files
        """
        directory_name = os.path.dirname(__file__)
        dummy_manga_site = MangaSite('test_site')
        dummy_manga = Manga('test_manga', 'test_manga_url', dummy_manga_site)
        dummy_chapter = Chapter(dummy_manga, 'test_chapter_title')

        self.assertTrue(dummy_chapter.number_of_pages() == 0)

        source_images_dir = os.path.join(directory_name, 'images')
        test_tmp_dir = os.path.join(directory_name, RESULTS_DIRECTORY)
        images_dir = dummy_chapter.get_download_path(test_tmp_dir)
        os.makedirs(images_dir, exist_ok=True)
        for file in os.listdir(source_images_dir):
            file_path = os.path.join(source_images_dir, file)
            if os.path.isfile(file_path):
                shutil.copy(file_path, images_dir)
        result, path_to_pdf = dummy_chapter.make_pdf(test_tmp_dir)

        self.assertTrue(result)
        self.assertTrue(dummy_chapter.number_of_pages() == 0)
        self.assertTrue(os.path.isfile(path_to_pdf))
        self.assertTrue(os.path.getsize(path_to_pdf) > 0)
        os.unlink(path_to_pdf)
        shutil.rmtree(test_tmp_dir, ignore_errors=True)
Example #2
0
    def test_chapter_1(self):
        dummy_manga_site = MangaSite('test_site')
        dummy_manga = Manga('test_manga', 'test_manga_url', dummy_manga_site)

        dummy_chapter1 = Chapter(dummy_manga)
        self.assertTrue(dummy_chapter1.number_of_pages() == 0)
        self.assertIsNone(dummy_chapter1.title)

        dummy_chapter2 = Chapter(dummy_manga, 'test_chapter_title')
        self.assertTrue(dummy_chapter2.title == 'test_chapter_title')
        dummy_chapter2.set_downloaded(True)
        self.assertTrue(dummy_chapter2.downloaded)
        self.assertTrue(dummy_chapter2.in_memory)
        dummy_chapter2.clear_state()
        self.assertFalse(dummy_chapter2.downloaded)
        self.assertFalse(dummy_chapter2.in_memory)
        try:
            dummy_chapter2.get_download_path(os.getcwd())
        except Exception as e:
            self.assertIsInstance(e, AttributeError)
            self.assertTrue("NoneType" in str(e))
        dump = dummy_chapter2.dump()
        self.assertIsInstance(dump, bytes)
        self.assertTrue(len(dump) > 0)