def update_novel_from_dto(self, novel: Novel, novel_dto: NovelDTO) -> Novel: novel.title = novel_dto.title novel.author = novel_dto.author novel.synopsis = novel_dto.synopsis novel.thumbnail_url = novel_dto.thumbnail_url novel.lang = novel_dto.lang return novel
def test_novel_from_dto(dto_adapter): novel_dto = NovelDTO( id=None, title="title", author="author", synopsis="a nice description", thumbnail_url="thumbnail", thumbnail_path=None, lang="language", url="link", last_updated=None, ) expected_novel = Novel( title="title", author="author", synopsis="a nice description", thumbnail_url="thumbnail", lang="language", ) expected_url = NovelUrl(url="link", ) actual_novel, actual_url = dto_adapter.novel_from_dto(novel_dto) for attrib in {"title", "author", "synopsis", "thumbnail_url", "lang"}: assert getattr(expected_novel, attrib) == getattr(actual_novel, attrib) for attrib in {"url"}: assert getattr(expected_url, attrib) == getattr(actual_url, attrib)
def test_get_thumbnail_path_no_suffix(source_service, novel_service): novel = Novel(id=1, thumbnail_url="https://my.site/local%20assets/image") path_service = PathService(data_dir, save_dir, config_dir, division_rules, novel_service, source_service) path = path_service.thumbnail_path(novel) assert data_dir / "1" / "cover" == path
def test_get_novel_path_no_source(source_service, novel_service): source_service.source_from_url.side_effect = SourceNotFoundException("") path_service = PathService(data_dir, save_dir, config_dir, division_rules, novel_service, source_service) path = path_service.novel_save_path(Novel(title="novel")) assert (save_dir / "novel").resolve() == path
def novel_from_dto(self, novel_dto: NovelDTO) -> Tuple[Novel, NovelUrl]: novel = Novel( title=novel_dto.title, author=novel_dto.author, synopsis=novel_dto.synopsis, thumbnail_url=novel_dto.thumbnail_url, lang=novel_dto.lang, ) url = NovelUrl(url=novel_dto.url, ) return novel, url
def test_get_novel_path_with_source(mocker, source_service, novel_service): source_gateway = mocker.patch( "novelsave.core.services.source.BaseSourceGateway") source_gateway.name = "source" source_service.source_from_url.return_value = source_gateway path_service = PathService(data_dir, save_dir, config_dir, division_rules, novel_service, source_service) path = path_service.novel_save_path(Novel(title="novel")) assert (save_dir / "source" / "novel").resolve() == path
def test_metadata_from_dto(dto_adapter): novel = Novel(id=1) metadata_dto = MetaDataDTO( name="name", value="value", namespace="ns", others={"role": "this"}, ) expected_metadata = MetaData( name="name", value="value", namespace="ns", others='{"role": "this"}', novel_id=novel.id, ) actual_metadata = dto_adapter.metadata_from_dto(novel, metadata_dto) for attrib in {"name", "value", "namespace", "others", "novel_id"}: assert getattr(expected_metadata, attrib) == getattr(actual_metadata, attrib)
def set_thumbnail_asset(self, novel: Novel, r_path: Path): if novel.thumbnail_path == str(r_path): return novel.thumbnail_path = str(r_path) self.session.commit()