updated unit tests; implemented volume property and related tests

This commit is contained in:
Bryan Bailey
2022-06-22 23:19:34 -04:00
parent e55cd132d4
commit 9c38e4a6eb
4 changed files with 26 additions and 18 deletions

View File

@@ -3,6 +3,7 @@
"Archiver", "Archiver",
"dbsuper", "dbsuper",
"draggable", "draggable",
"errored",
"excaliber", "excaliber",
"mangadex", "mangadex",
"readallcomics", "readallcomics",

View File

@@ -50,8 +50,6 @@ def init():
@yoink.command() @yoink.command()
# @click.option('-c', '--comic', is_flag=True, help='Download a Comic file')
# @click.option('-t', '--torrent', is_flag=True, help='Download a Torrent')
@click.option('-s', '--series', is_flag=True, help='Download the entire series') @click.option('-s', '--series', is_flag=True, help='Download the entire series')
@click.argument('url') @click.argument('url')
def download(url, series): def download(url, series):

View File

@@ -82,7 +82,14 @@ class Comic(Scrapable):
@property @property
def volume(self) -> int: def volume(self) -> int:
return delimiter = ' v'
try:
if self.title.find(delimiter) and self.title[self.title.index(delimiter) + 2].isdigit():
return self.title[self.title.index(delimiter) + 2]
else:
return 1
except ValueError:
return 1
@property @property
def next(self) -> str: def next(self) -> str:
@@ -160,11 +167,13 @@ def clean_up(comic: Comic):
if __name__ == '__main__': if __name__ == '__main__':
comic = Comic('http://www.readallcomics.com/static-season-one-4-2021/') # all links # comic = Comic('http://www.readallcomics.com/static-season-one-4-2021/') # all links
comic = Comic('http://readallcomics.com/x-men-v6-12-2022/')
# comic = Comic('http://readallcomics.com/static-season-one-001-2021/') # no prev link # comic = Comic('http://readallcomics.com/static-season-one-001-2021/') # no prev link
# comic = Comic('http://readallcomics.com/static-season-one-6-2022/') # no next link # comic = Comic('http://readallcomics.com/static-season-one-6-2022/') # no next link
# comic = Comic('http://readallcomics.com/superman-vs-lobo-4-2022/') # comic = Comic('http://readallcomics.com/superman-vs-lobo-4-2022/')
# test_comic_b = 'http://readallcomics.com/captain-marvel-vs-rogue-2021-part-1/' # comic = Comic('http://readallcomics.com/captain-marvel-vs-rogue-2021-part-1/')
print(comic.volume)
# print(comic.next) # print(comic.next)
# print(comic.prev) # print(comic.prev)
# print(comic.issue_number) # print(comic.issue_number)

View File

@@ -5,7 +5,7 @@ import unittest
from shutil import rmtree from shutil import rmtree
from yoink.config import app_root, library_path, config_path, skippable_images, supported_sites, required_archive_files from yoink.config import app_root, library_path, config_path, skippable_images, supported_sites, required_archive_files
from yoink.comic import Comic, ComicArchiver from yoink.comic import Comic, download_comic_files, generate_archive, clean_up
from yoink.scraper import Scrapable from yoink.scraper import Scrapable
@@ -15,13 +15,13 @@ class BasicTestCase(unittest.TestCase):
self.test_comic = 'http://readallcomics.com/static-season-one-6-2022/' self.test_comic = 'http://readallcomics.com/static-season-one-6-2022/'
self.test_comic_b = 'http://readallcomics.com/captain-marvel-vs-rogue-2021-part-1/' self.test_comic_b = 'http://readallcomics.com/captain-marvel-vs-rogue-2021-part-1/'
self.comic = Comic(self.test_comic) self.comic = Comic(self.test_comic)
self.archiver = ComicArchiver(self.comic)
self.remove_queue = [] self.remove_queue = []
self.expected_title = 'Static Season One 6 (2022)' self.expected_title = 'Static Season One 6 (2022)'
self.expected_title_b = 'Captain Marvel vs. Rogue (2021 Part 1)' self.expected_title_b = 'Captain Marvel vs. Rogue (2021 Part 1)'
self.expected_category = 'Static: Season One' self.expected_category = 'Static: Season One'
self.expected_category_b = 'Captain Marvel vs. Rogue' self.expected_category_b = 'Captain Marvel vs. Rogue'
self.expected_issue_num = 6 self.expected_issue_num = 6
self.expected_vol_num = 1
self.expected_next_url = None self.expected_next_url = None
self.expected_prev_url = 'http://readallcomics.com/static-season-one-5-2022/' self.expected_prev_url = 'http://readallcomics.com/static-season-one-5-2022/'
self.erroneous_comic = 'http://readallcomics.com/static-season-one-4-2021/' self.erroneous_comic = 'http://readallcomics.com/static-season-one-4-2021/'
@@ -39,28 +39,28 @@ class BasicTestCase(unittest.TestCase):
def test_001_comic_has_valid_title(self): def test_001_comic_has_valid_title(self):
self.assertEqual(self.expected_title, self.comic.title) self.assertEqual(self.expected_title, self.comic.title)
def test_002_comic_has_valid_category(self): def test_002_comic_has_valid_volume_numer(self):
self.assertEqual(self.expected_vol_num, self.comic.volume)
def test_003_comic_has_valid_category(self):
self.assertEqual(self.expected_category, self.comic.category) self.assertEqual(self.expected_category, self.comic.category)
def test_003_empty_comic_folder(self): def test_004_empty_comic_folder(self):
self.assertEqual(len(os.listdir(os.path.join(library_path, 'comics'))), 0) self.assertEqual(len(os.listdir(os.path.join(library_path, 'comics'))), 0)
def test_004_comic_folder_created_and_populated(self): def test_005_comic_folder_created_and_populated(self):
self.archiver.download() download_comic_files(self.comic)
self.assertTrue(os.path.exists(os.path.join(library_path, f'comics/{self.comic.title}'))) self.assertTrue(os.path.exists(os.path.join(library_path, f'comics/{self.comic.title}')))
self.assertGreater(len(os.listdir(os.path.join(library_path, f'comics/{self.comic.title}'))), 0) self.assertGreater(len(os.listdir(os.path.join(library_path, f'comics/{self.comic.title}'))), 0)
def test_005_comic_archive_generated(self): def test_006_comic_archive_generated(self):
self.archiver.generate_archive() generate_archive(self.comic)
self.assertTrue(os.path.exists(os.path.join(library_path, f'comics/{self.comic.title}/{self.comic.title}.cbr'))) self.assertTrue(os.path.exists(os.path.join(library_path, f'comics/{self.comic.title}/{self.comic.title}.cbr')))
def test_006_folder_cleaned_after_archive_generation(self): def test_007_folder_cleaned_after_archive_generation(self):
self.archiver.cleanup_worktree() clean_up(self.comic)
self.assertLessEqual(len(os.listdir(os.path.join(library_path, f'comics/{self.comic.title}'))), 3) self.assertLessEqual(len(os.listdir(os.path.join(library_path, f'comics/{self.comic.title}'))), 3)
def test_007_comic_instance_has_archiver(self):
self.assertIsInstance(self.comic.archiver, ComicArchiver)
def test_008_comic_is_subclass_scrapable(self): def test_008_comic_is_subclass_scrapable(self):
self.assertTrue(issubclass(Comic, Scrapable)) self.assertTrue(issubclass(Comic, Scrapable))