def test_with_existing_not_in_service(self): """ Should not count as manga that already exist in the service as existing """ prefix = self.get_str_id() title1 = f'{prefix}_test 1' title2 = f'{prefix}_test 2' title3 = f'{prefix}_test 3' m1 = Manga(title=title1) # exists m2 = Manga(title=title2) # exists m3 = Manga(title=title3) # does not exist m11 = Manga(title=title1) m22 = MangaService(title=title2, service_id=DummyScraper2.ID, disabled=False, title_id=self.get_str_id()) m33 = MangaService(title=title3, service_id=DummyScraper.ID, disabled=False, title_id=self.get_str_id()) self.dbutil.add_new_manga(m11) self.dbutil.add_manga_service(m22, add_manga=True) self.dbutil.add_manga_service(m33, add_manga=True) mangas = [m1, m2, m3] exists, not_exists = self.dbutil.split_existing_manga( DummyScraper.ID, mangas) self.assertEqual(exists, [m1, m2]) self.assertEqual(not_exists, [m3])
def test_with_no_existing(self): prefix = self.get_str_id() m1 = Manga(title=f'{prefix}_test 1') m2 = Manga(title=f'{prefix}_test 2') mangas = [m1, m2] exists, not_exists = self.dbutil.split_existing_manga( DummyScraper.ID, mangas) self.assertFalse(exists) self.assertEqual(not_exists, mangas)
def find_manga_by_title(self, title: str, *, cur: Cursor = NotImplemented) -> Optional[Manga]: sql = 'SELECT * FROM manga WHERE title=%s LIMIT 1' cur.execute(sql, (title, )) row = cur.fetchone() return None if not row else Manga(**row)
def get_manga(self, manga_id: int, *, cur: Cursor = NotImplemented) -> Optional[Manga]: """ Get manga object from database """ sql = 'SELECT * FROM manga WHERE manga_id=%s' cur.execute(sql, (manga_id, )) row = cur.fetchone() return Manga(**row) if row else None
def test_with_existing_in_service(self): """ Should not count as manga that already exist in the service as existing """ prefix = self.get_str_id() m1 = MangaService(title=f'{prefix}_test 1', service_id=DummyScraper.ID, disabled=False, title_id=self.get_str_id()) m2 = Manga(title=f'{prefix}_test 2') self.dbutil.add_manga_service(m1, add_manga=True) mangas = [m1, m2] exists, not_exists = self.dbutil.split_existing_manga( DummyScraper.ID, mangas) self.assertFalse(exists) self.assertEqual(not_exists, [m1, m2])
def test_add_new_manga_service_all_properties(self): title_id = self.get_str_id() manga = MangaService(service_id=DummyScraper.ID, disabled=True, title_id=title_id, last_check=self.utcnow(), next_update=self.utcnow(), feed_url='test value', latest_decimal=1, title=f'{title_id}_manga', release_interval=timedelta(hours=1), latest_release=self.utcnow(), estimated_release=self.utcnow(), latest_chapter=5, views=10) self.dbutil.add_manga_service(manga, add_manga=True) # Assert inserted rows map and match correctly self.assertIsNotNone(manga.manga_id) self.assertEqual( self.dbutil.get_manga_service(manga.service_id, title_id), manga) self.assertEqual(self.dbutil.get_manga(manga.manga_id), Manga(**manga.dict()))
def create_manga(self, title: str = None) -> Manga: ms = Manga(title=title or self.gen_title()) return self.dbutil.add_new_manga(ms)
def get_unique_manga(self) -> Manga: return Manga(title=f'{self.get_str_id()}_manga')