From e37a9ee28c28c93af05b9aa762fa4cc855c4c671 Mon Sep 17 00:00:00 2001 From: obar1 <387386+obar1@users.noreply.github.com> Date: Wed, 3 Apr 2024 09:57:47 +0200 Subject: [PATCH] 100 add relative folder path for img and pdf etc (#105) --- zero_to_one_hundred/models/meta_book.py | 14 +++- zero_to_one_hundred/models/section.py | 2 +- zero_to_one_hundred/models/toc.py | 64 ++++++++++--------- .../repository/sb_persist_fs.py | 4 -- zero_to_one_hundred/tests/conftest.py | 19 +++++- .../tests/repository/__init__.py | 0 .../tests/repository/ztoh_process_fs.py | 7 ++ .../tests/test_create_section_processor.py | 9 ++- .../tests/test_done_section_processor.py | 9 ++- .../tests/test_help_processor.py | 13 +--- zero_to_one_hundred/tests/test_map.py | 32 +++++++++- zero_to_one_hundred/tests/test_readme_md.py | 15 +++++ .../tests/test_refresh_links_processor.py | 7 +- .../tests/test_refresh_map_processor.py | 7 +- zero_to_one_hundred/tests/test_section.py | 9 +++ zero_to_one_hundred/tests_sb/conftest.py | 17 ++++- .../tests_sb/repository/__init__.py | 0 .../tests_sb/repository/sb_process_fs.py | 12 ++++ .../test_create_meta_book_processor.py | 11 ++-- .../tests_sb/test_meta_book.py | 5 +- zero_to_one_hundred/tests_sb/test_metadata.py | 5 +- .../tests_sb/test_refresh_toc_processor.py | 9 ++- .../tests_sb/test_sb_factory_provider.py | 10 +-- zero_to_one_hundred/tests_sb/test_toc.py | 40 ++++++++++-- 24 files changed, 214 insertions(+), 106 deletions(-) create mode 100644 zero_to_one_hundred/tests/repository/__init__.py create mode 100644 zero_to_one_hundred/tests/repository/ztoh_process_fs.py create mode 100644 zero_to_one_hundred/tests_sb/repository/__init__.py create mode 100644 zero_to_one_hundred/tests_sb/repository/sb_process_fs.py diff --git a/zero_to_one_hundred/models/meta_book.py b/zero_to_one_hundred/models/meta_book.py index 0f54d31..f9360b3 100644 --- a/zero_to_one_hundred/models/meta_book.py +++ b/zero_to_one_hundred/models/meta_book.py @@ -6,9 +6,10 @@ from zero_to_one_hundred.repository.sb_persist_fs import SBPersistFS from zero_to_one_hundred.repository.sb_process_fs import SBProcessFS from zero_to_one_hundred.validator.validator import Validator +from zero_to_one_hundred.views.markdown_renderer import MarkdownRenderer -class MetaBook: +class MetaBook(MarkdownRenderer): epub_suffix = ".epub" HTTP_OREILLY_COVER = "https://learning.oreilly.com/library/cover" HTTP_OREILLY_LIBRARY = "https://learning.oreilly.com/library/" @@ -36,8 +37,11 @@ def __init__( self.path_epub = f"{self.contents_path}/{self.isbn}.epub" self.path_pdf = f"{self.contents_path}/{self.isbn}.pdf" self.path_img = f"{self.contents_path}/{self.isbn}.png" + self.path_epub_as_md = self.path_as_md(f"./{self.isbn}/{self.isbn}.epub") + self.path_pdf_as_md = self.path_as_md(f"./{self.isbn}/{self.isbn}.pdf") + self.path_img_as_md = self.path_as_md(f"./{self.isbn}/{self.isbn}.png") - def __repr__(self): + def asMarkDown(self): return f"MetaBook {self.http_url}, {self.isbn} {self.contents_path}" @classmethod @@ -128,3 +132,9 @@ def write_pdf(self, fn): def write_splitter_pdf(self, fn, split_pdf_pages): self.persist_fs.write_splitter_pdf(fn, split_pdf_pages) + + def path_as_md(self, a_path): + """ + use relative path and convert " " to %20 + """ + return a_path.replace(" ", "%20") diff --git a/zero_to_one_hundred/models/section.py b/zero_to_one_hundred/models/section.py index a48bf9d..f8d5828 100644 --- a/zero_to_one_hundred/models/section.py +++ b/zero_to_one_hundred/models/section.py @@ -235,7 +235,7 @@ def get_format_as_md(self): res = next(item for item in a if item is not None) except StopIteration: return "" - return res + return res def __eq__(self, other): if other is self: diff --git a/zero_to_one_hundred/models/toc.py b/zero_to_one_hundred/models/toc.py index fbb2b5e..9094f4f 100644 --- a/zero_to_one_hundred/models/toc.py +++ b/zero_to_one_hundred/models/toc.py @@ -3,9 +3,11 @@ from zero_to_one_hundred.configs.sb_config_map import SBConfigMap from zero_to_one_hundred.models.meta_book import MetaBook +from zero_to_one_hundred.repository.sb_persist_fs import SBPersistFS +from zero_to_one_hundred.views.markdown_renderer import MarkdownRenderer -class Toc: +class Toc(MarkdownRenderer): """Toc: toc md with list of meta_book as found in fs """ @@ -13,7 +15,7 @@ class Toc: def __init__( self, config_map: SBConfigMap, - persist_fs, + persist_fs: SBPersistFS, process_fs, meta_books: List[MetaBook], ): @@ -26,7 +28,22 @@ def __init__( def __repr__(self): return f"Toc {self.readme_md}, {self.meta_books}" - def __repr_flatten(self, meta_books: List[MetaBook]) -> str: + @classmethod + def build_from_dirs( + cls, config_map, persist_fs, process_fs, dirs: List[str] + ) -> List[MetaBook]: + """from a list of dirs created return the a MetaBook + m> org http is lost + """ + res = [ + MetaBook.build_from_dir(config_map, persist_fs, process_fs, curr_dir) + for curr_dir in dirs + if curr_dir is not None + ] + print(res) + return res + + def asMarkDown(self): def flatten_meta_book(meta_book: MetaBook): print(f"flatten_meta_book {meta_book}") json = meta_book.read_json().replace( @@ -41,43 +58,32 @@ def flatten_meta_book(meta_book: MetaBook): res = "|".join( [ f'**{meta_book.isbn}**', - f"![`img`]({self.persist_fs.render_path(meta_book.path_img)})", - f"[`epub`]({self.persist_fs.render_path(meta_book.path_epub)})", - f"[`pdf`]({self.persist_fs.render_path(meta_book.path_pdf)})", + f"![`img`]({meta_book.path_img_as_md})", + f"[`epub`]({meta_book.path_epub_as_md})", + f"[`pdf`]({meta_book.path_pdf_as_md})", f"{json}", f"{status}", ] ) - return res - flattened_meta_book = [flatten_meta_book(mb) for mb in meta_books] - return "\n".join(flattened_meta_book) + return "|" + res + "|" + " " - @classmethod - def build_from_dirs( - cls, config_map, persist_fs, process_fs, dirs: List[str] - ) -> List[MetaBook]: - """from a list of dirs created return the a MetaBook - m> org http is lost - """ - res = [ - MetaBook.build_from_dir(config_map, persist_fs, process_fs, curr_dir) - for curr_dir in dirs - if curr_dir is not None - ] - print(res) - return res + flattened_meta_book = [flatten_meta_book(mb) for mb in self.meta_books] + backslash_n_char = "\n" - def write(self): - txt = [] - txt.append( + md = [] + md.append( f""" # TOC ## `{len(self.meta_books)}` books ### {self.process_fs.get_now()} -| ISBN | | | | `json-contents` | `status` | +| ISBN | img | epub | pdf | `json-contents` | `status` | |--- |--- |--- |--- |--- |--- | -{self.__repr_flatten(self.meta_books)} +{backslash_n_char.join(flattened_meta_book)} """ ) - return self.persist_fs.write_file(self.readme_md, txt) + return md + + def write(self): + md = self.asMarkDown() + return self.persist_fs.write_file(self.readme_md, md) diff --git a/zero_to_one_hundred/repository/sb_persist_fs.py b/zero_to_one_hundred/repository/sb_persist_fs.py index c7fe2b9..7061581 100644 --- a/zero_to_one_hundred/repository/sb_persist_fs.py +++ b/zero_to_one_hundred/repository/sb_persist_fs.py @@ -28,10 +28,6 @@ def is_relative_path(cls, path): def render_json(cls, txt: str): return txt.replace('"', ' " ').replace("\n", "
") - @classmethod - def render_path(cls, txt: str): - return txt.replace(" ", "%20") - @classmethod def get_epub_path(cls, download_engine_books_path, isbn, epub_suffix): """find the actual path into the path given the isbn diff --git a/zero_to_one_hundred/tests/conftest.py b/zero_to_one_hundred/tests/conftest.py index bd0a61e..0b9489f 100644 --- a/zero_to_one_hundred/tests/conftest.py +++ b/zero_to_one_hundred/tests/conftest.py @@ -1,15 +1,17 @@ # pylint: disable=W0621,W0613 import os +import string from unittest import mock import pytest from zero_to_one_hundred.configs.a_config_map import AConfigMap from zero_to_one_hundred.configs.ztoh_config_map import ZTOHConfigMap +from zero_to_one_hundred.factories.ztoh_factory import ZTOHFactory from zero_to_one_hundred.factories.ztoh_factory_provider import ZTOHFactoryProvider from zero_to_one_hundred.repository.ztoh_persist_fs import ZTOHPersistFS -from zero_to_one_hundred.repository.ztoh_process_fs import ZTOHProcessFS +from zero_to_one_hundred.tests.repository.ztoh_process_fs import ZTOHProcessFS @pytest.fixture @@ -97,12 +99,12 @@ def env_datacamp_map_yaml(get_datacamp_map_yaml_path): @pytest.fixture -def persist_fs() -> ZTOHPersistFS: +def persist_fs(): yield ZTOHPersistFS() @pytest.fixture -def process_fs() -> ZTOHProcessFS: +def process_fs(): yield ZTOHProcessFS() @@ -130,6 +132,11 @@ def get_datacamp_config_map( return ZTOHConfigMap(persist_fs) +@pytest.fixture +def get_factory(env_map_yaml, persist_fs, process_fs): + return ZTOHFactory(get_config_map, persist_fs, process_fs) + + @pytest.fixture def get_factory_provider(env_map_yaml, persist_fs, process_fs): return ZTOHFactoryProvider(persist_fs, process_fs) @@ -148,3 +155,9 @@ def simple_dir(): @pytest.fixture def dir_tree(): return "https§§§cloud.google.com§sections" + + +def str_relaxed(s1): + remove = string.whitespace + mapping = {ord(c): None for c in remove} + return s1.translate(mapping) diff --git a/zero_to_one_hundred/tests/repository/__init__.py b/zero_to_one_hundred/tests/repository/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/zero_to_one_hundred/tests/repository/ztoh_process_fs.py b/zero_to_one_hundred/tests/repository/ztoh_process_fs.py new file mode 100644 index 0000000..5b0ae3c --- /dev/null +++ b/zero_to_one_hundred/tests/repository/ztoh_process_fs.py @@ -0,0 +1,7 @@ +from zero_to_one_hundred.repository.ztoh_process_fs import ZTOHProcessFS as zfs + + +class ZTOHProcessFS(zfs): + @staticmethod + def get_now(): + return "2099/01/01 - 00:00:00" diff --git a/zero_to_one_hundred/tests/test_create_section_processor.py b/zero_to_one_hundred/tests/test_create_section_processor.py index 367133a..05d56b0 100644 --- a/zero_to_one_hundred/tests/test_create_section_processor.py +++ b/zero_to_one_hundred/tests/test_create_section_processor.py @@ -1,14 +1,13 @@ from unittest.mock import patch -from zero_to_one_hundred.factories.ztoh_factory import ZTOHFactory from zero_to_one_hundred.processors.create_section_processor import ( CreateSectionProcessor, ) @patch("zero_to_one_hundred.factories.ztoh_factory.ZTOHFactory.get_processor") -def test_process(get_config_map, persist_fs, process_fs, http_url): - actual: CreateSectionProcessor = ZTOHFactory( - get_config_map, persist_fs, process_fs - ).get_processor([None, "create_section", http_url]) +def test_process(get_config_map, get_factory, http_url): + actual: CreateSectionProcessor = get_factory.get_processor( + [None, "create_section", http_url] + ) for p in actual: p.process() diff --git a/zero_to_one_hundred/tests/test_done_section_processor.py b/zero_to_one_hundred/tests/test_done_section_processor.py index 0e435ae..028c7c8 100644 --- a/zero_to_one_hundred/tests/test_done_section_processor.py +++ b/zero_to_one_hundred/tests/test_done_section_processor.py @@ -1,12 +1,11 @@ from unittest.mock import patch -from zero_to_one_hundred.factories.ztoh_factory import ZTOHFactory from zero_to_one_hundred.processors.done_section_processor import DoneSectionProcessor @patch("zero_to_one_hundred.factories.ztoh_factory.ZTOHFactory.get_processor") -def test_process(get_config_map, persist_fs, process_fs, http_url): - actual: DoneSectionProcessor = ZTOHFactory( - get_config_map, persist_fs, process_fs - ).get_processor([None, "done_section", http_url]) +def test_process(get_config_map, get_factory, http_url): + actual: DoneSectionProcessor = get_factory.get_processor( + [None, "done_section", http_url] + ) for p in actual: p.process() diff --git a/zero_to_one_hundred/tests/test_help_processor.py b/zero_to_one_hundred/tests/test_help_processor.py index 210444c..dadfab3 100644 --- a/zero_to_one_hundred/tests/test_help_processor.py +++ b/zero_to_one_hundred/tests/test_help_processor.py @@ -1,16 +1,7 @@ -from zero_to_one_hundred.factories.ztoh_factory import ZTOHFactory from zero_to_one_hundred.processors.help_processor import HelpProcessor -def test_process( - get_config_map, - persist_fs, - process_fs, -): - actual: HelpProcessor = ZTOHFactory( - get_config_map, - persist_fs, - process_fs, - ).get_processor([None, "help"]) +def test_process(get_factory): + actual: HelpProcessor = get_factory.get_processor([None, "help"]) for p in actual: p.process() diff --git a/zero_to_one_hundred/tests/test_map.py b/zero_to_one_hundred/tests/test_map.py index 48b1c95..51f8b86 100644 --- a/zero_to_one_hundred/tests/test_map.py +++ b/zero_to_one_hundred/tests/test_map.py @@ -3,13 +3,39 @@ from zero_to_one_hundred.models.map import Map from zero_to_one_hundred.models.section import Section -from zero_to_one_hundred.repository.ztoh_persist_fs import ZTOHPersistFS as persist_fs -from zero_to_one_hundred.repository.ztoh_process_fs import ZTOHProcessFS as process_fs -def test_write(get_config_map, http_url, http_url_2): +def test_write(get_config_map, persist_fs, process_fs, http_url, http_url_2): sections: List[Section] = [ Section(get_config_map, persist_fs, process_fs, http_url, False), Section(get_config_map, persist_fs, process_fs, http_url_2, False), ] actual = Map(get_config_map, persist_fs, sections=sections) + + +def test_asMarkDown(get_config_map, persist_fs, process_fs, http_url, http_url_2): + sections: List[Section] = [ + Section(get_config_map, persist_fs, process_fs, http_url, False), + Section(get_config_map, persist_fs, process_fs, http_url_2, False), + ] + actual = Map(get_config_map, persist_fs, sections=sections) + current = actual.asMarkDown() + expected = """ +# map toc.md, 2 + +## sorted: False + + +## legend: + +| footprints | completed | +|---|---| +| :footprints: | :green_heart: | + + + + +1.[`here`](./0to100/https§§§cloud.google.com§abc/readme.md) :footprints: +1.[`here`](./0to100/https§§§cloud.google.com§zzz/readme.md) :footprints: +""" + assert current.strip() == expected.strip() diff --git a/zero_to_one_hundred/tests/test_readme_md.py b/zero_to_one_hundred/tests/test_readme_md.py index b2916ef..7c2f0e7 100644 --- a/zero_to_one_hundred/tests/test_readme_md.py +++ b/zero_to_one_hundred/tests/test_readme_md.py @@ -10,3 +10,18 @@ def test_refresh_links(get_config_map, persist_fs, process_fs, http_url): Section.from_http_url_to_dir, http_url, ) + + +def test_asMarkDown(get_config_map, persist_fs, process_fs, http_url): + actual = ReadMeMD( + get_config_map, + persist_fs, + process_fs, + Section.from_http_url_to_dir, + http_url, + ) + current = actual.asMarkDown() + assert ( + current + == "ReadMeMD ./0to100/https§§§cloud.google.com§abc/readme.md, https§§§cloud.google.com§abc https://cloud.google.com/abc" + ) diff --git a/zero_to_one_hundred/tests/test_refresh_links_processor.py b/zero_to_one_hundred/tests/test_refresh_links_processor.py index 8ac60c2..5b8841a 100644 --- a/zero_to_one_hundred/tests/test_refresh_links_processor.py +++ b/zero_to_one_hundred/tests/test_refresh_links_processor.py @@ -1,12 +1,9 @@ from unittest.mock import patch -from zero_to_one_hundred.factories.ztoh_factory import ZTOHFactory from zero_to_one_hundred.processors.refresh_links_processor import RefreshLinksProcessor @patch("zero_to_one_hundred.factories.ztoh_factory.ZTOHFactory.get_processor") -def test_process(get_config_map, persist_fs, process_fs): - actual: RefreshLinksProcessor = ZTOHFactory( - get_config_map, persist_fs, process_fs - ).get_processor([None, "refresh_links"]) +def test_process(get_factory): + actual: RefreshLinksProcessor = get_factory.get_processor([None, "refresh_links"]) for p in actual: p.process() diff --git a/zero_to_one_hundred/tests/test_refresh_map_processor.py b/zero_to_one_hundred/tests/test_refresh_map_processor.py index 0f8fe8e..b5ab85e 100644 --- a/zero_to_one_hundred/tests/test_refresh_map_processor.py +++ b/zero_to_one_hundred/tests/test_refresh_map_processor.py @@ -1,12 +1,9 @@ from unittest.mock import patch -from zero_to_one_hundred.factories.ztoh_factory import ZTOHFactory from zero_to_one_hundred.processors.refresh_map_processor import RefreshMapProcessor @patch("zero_to_one_hundred.factories.ztoh_factory.ZTOHFactory.get_processor") -def test_process(get_config_map, persist_fs, process_fs): - actual: RefreshMapProcessor = ZTOHFactory( - get_config_map, persist_fs, process_fs - ).get_processor([None, "refresh_map"]) +def test_process(get_factory): + actual: RefreshMapProcessor = get_factory.get_processor([None, "refresh_map"]) for p in actual: p.process() diff --git a/zero_to_one_hundred/tests/test_section.py b/zero_to_one_hundred/tests/test_section.py index 250e892..eb2a984 100644 --- a/zero_to_one_hundred/tests/test_section.py +++ b/zero_to_one_hundred/tests/test_section.py @@ -74,3 +74,12 @@ def test_gcp_get_format_as_md(get_gcp_config_map, persist_fs, process_fs): persist_fs, process_fs, get_gcp_config_map, http_url ) assert actual.get_format_as_md == """:snake:""" + + +def test_asMarkDown(get_config_map, persist_fs, process_fs, http_url): + actual = Section(get_config_map, persist_fs, process_fs, http_url) + current = actual.asMarkDown() + assert ( + current + == "1. [`here`](./0to100/https§§§cloud.google.com§abc/readme.md) :footprints:" + ) diff --git a/zero_to_one_hundred/tests_sb/conftest.py b/zero_to_one_hundred/tests_sb/conftest.py index 05d1432..ce2c648 100644 --- a/zero_to_one_hundred/tests_sb/conftest.py +++ b/zero_to_one_hundred/tests_sb/conftest.py @@ -7,9 +7,10 @@ from zero_to_one_hundred.configs.a_config_map import AConfigMap from zero_to_one_hundred.configs.sb_config_map import SBConfigMap +from zero_to_one_hundred.factories.sb_factory import SBFactory from zero_to_one_hundred.factories.sb_factory_provider import SBFactoryProvider from zero_to_one_hundred.repository.sb_persist_fs import SBPersistFS -from zero_to_one_hundred.repository.sb_process_fs import SBProcessFS +from zero_to_one_hundred.tests_sb.repository.sb_process_fs import SBProcessFS @pytest.fixture @@ -17,6 +18,11 @@ def http_url(): yield "https://learning.oreilly.com/library/view/the-pragmatic-programmer/9780135956977/" +@pytest.fixture +def http_url2(): + yield "https://learning.oreilly.com/library/view/clean-code-in/9781800560215/" + + @pytest.fixture def isbn(): yield "9780135956977" @@ -69,12 +75,12 @@ def env_map_yaml(get_map_yaml_path): @pytest.fixture -def persist_fs() -> SBPersistFS: +def persist_fs(): yield SBPersistFS() @pytest.fixture -def process_fs() -> SBProcessFS: +def process_fs(): yield SBProcessFS() @@ -86,3 +92,8 @@ def get_config_map(env_map_yaml, get_map_yaml_path, persist_fs): @pytest.fixture def get_factory_provider(env_map_yaml): return SBFactoryProvider(SBPersistFS, SBProcessFS) + + +@pytest.fixture +def get_factory(env_map_yaml, persist_fs, process_fs): + return SBFactory(env_map_yaml, persist_fs, process_fs) diff --git a/zero_to_one_hundred/tests_sb/repository/__init__.py b/zero_to_one_hundred/tests_sb/repository/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/zero_to_one_hundred/tests_sb/repository/sb_process_fs.py b/zero_to_one_hundred/tests_sb/repository/sb_process_fs.py new file mode 100644 index 0000000..33a18c3 --- /dev/null +++ b/zero_to_one_hundred/tests_sb/repository/sb_process_fs.py @@ -0,0 +1,12 @@ +from zero_to_one_hundred.configs.sb_config_map import SBConfigMap +from zero_to_one_hundred.tests.repository.ztoh_process_fs import ZTOHProcessFS + + +class SBProcessFS(ZTOHProcessFS): + @classmethod + def write_img(cls, path_img, http_url_img): + pass + + @classmethod + def write_epub(cls, config_map: SBConfigMap, path_epub, isbn): + pass diff --git a/zero_to_one_hundred/tests_sb/test_create_meta_book_processor.py b/zero_to_one_hundred/tests_sb/test_create_meta_book_processor.py index 9c10d3d..5163e27 100644 --- a/zero_to_one_hundred/tests_sb/test_create_meta_book_processor.py +++ b/zero_to_one_hundred/tests_sb/test_create_meta_book_processor.py @@ -1,19 +1,16 @@ from subprocess import CalledProcessError from unittest.mock import patch -from zero_to_one_hundred.factories.sb_factory import SBFactory from zero_to_one_hundred.processors.snatch_book_processor import ( SnatchBookProcessor, ) @patch("zero_to_one_hundred.factories.sb_factory.SBFactory.get_processor") -def test_process(get_config_map, persist_fs, process_fs, http_url): - actual: SnatchBookProcessor = SBFactory( - get_config_map, - persist_fs, - process_fs, - ).get_processor([None, "snatch_book", http_url]) +def test_process(get_factory, http_url): + actual: SnatchBookProcessor = get_factory.get_processor( + [None, "snatch_book", http_url] + ) for p in actual: try: p.process() diff --git a/zero_to_one_hundred/tests_sb/test_meta_book.py b/zero_to_one_hundred/tests_sb/test_meta_book.py index 2aa1150..b4fb23d 100644 --- a/zero_to_one_hundred/tests_sb/test_meta_book.py +++ b/zero_to_one_hundred/tests_sb/test_meta_book.py @@ -1,11 +1,10 @@ -from zero_to_one_hundred.configs.sb_config_map import SBConfigMap from zero_to_one_hundred.models.meta_book import MetaBook # pylint: disable=W0613 def test_init(get_config_map, persist_fs, process_fs, http_url): actual = MetaBook( - SBConfigMap(persist_fs), + get_config_map, persist_fs, process_fs, http_url, @@ -20,7 +19,7 @@ def test_init(get_config_map, persist_fs, process_fs, http_url): def test_build_from_dir(get_config_map, persist_fs, process_fs): assert ( MetaBook.build_from_dir( - SBConfigMap(persist_fs), + get_config_map, persist_fs, process_fs, "./books/9780135956977", diff --git a/zero_to_one_hundred/tests_sb/test_metadata.py b/zero_to_one_hundred/tests_sb/test_metadata.py index 83b7e3e..64672e0 100644 --- a/zero_to_one_hundred/tests_sb/test_metadata.py +++ b/zero_to_one_hundred/tests_sb/test_metadata.py @@ -1,11 +1,10 @@ -from zero_to_one_hundred.configs.sb_config_map import SBConfigMap from zero_to_one_hundred.models.meta_book import MetaBook from zero_to_one_hundred.models.metadata import Metadata def test_init(get_config_map, persist_fs, process_fs, http_url, isbn): actual = Metadata( - SBConfigMap(persist_fs), + get_config_map, persist_fs, process_fs, MetaBook.get_isbn, @@ -19,7 +18,7 @@ def test_init(get_config_map, persist_fs, process_fs, http_url, isbn): def test_get_page_perc(get_config_map, persist_fs, process_fs, http_url): actual = Metadata( - SBConfigMap(persist_fs), + get_config_map, persist_fs, process_fs, MetaBook.get_isbn, diff --git a/zero_to_one_hundred/tests_sb/test_refresh_toc_processor.py b/zero_to_one_hundred/tests_sb/test_refresh_toc_processor.py index 51fcb43..186f79c 100644 --- a/zero_to_one_hundred/tests_sb/test_refresh_toc_processor.py +++ b/zero_to_one_hundred/tests_sb/test_refresh_toc_processor.py @@ -1,15 +1,14 @@ from unittest.mock import patch -from zero_to_one_hundred.factories.sb_factory import SBFactory from zero_to_one_hundred.processors.refresh_toc_processor import ( RefreshTocProcessor, ) @patch("zero_to_one_hundred.factories.sb_factory.SBFactory.get_processor") -def test_process(get_config_map, persist_fs, process_fs): - actual: RefreshTocProcessor = SBFactory( - get_config_map, persist_fs, process_fs - ).get_processor([None, "refresh_toc"]) +def test_process(get_factory_provider): + actual: RefreshTocProcessor = get_factory_provider.get_processor( + [None, "refresh_toc"] + ) for p in actual: p.process() diff --git a/zero_to_one_hundred/tests_sb/test_sb_factory_provider.py b/zero_to_one_hundred/tests_sb/test_sb_factory_provider.py index 968afc0..8d375b1 100644 --- a/zero_to_one_hundred/tests_sb/test_sb_factory_provider.py +++ b/zero_to_one_hundred/tests_sb/test_sb_factory_provider.py @@ -1,15 +1,9 @@ -from zero_to_one_hundred.factories.sb_factory import SBFactory - from zero_to_one_hundred.factories.sb_factory_provider import SBFactoryProvider # pylint: disable=W0621 -def test_pass( - get_config_map, - persist_fs, - process_fs, -): +def test_pass(get_config_map, persist_fs, process_fs, get_factory): actual = SBFactoryProvider(persist_fs, process_fs) - assert isinstance(actual.provide(), SBFactory) + assert isinstance(actual.provide(), type(get_factory)) diff --git a/zero_to_one_hundred/tests_sb/test_toc.py b/zero_to_one_hundred/tests_sb/test_toc.py index 9aebae8..602c7f2 100644 --- a/zero_to_one_hundred/tests_sb/test_toc.py +++ b/zero_to_one_hundred/tests_sb/test_toc.py @@ -1,27 +1,59 @@ -from zero_to_one_hundred.configs.sb_config_map import SBConfigMap from zero_to_one_hundred.models.meta_book import MetaBook from zero_to_one_hundred.models.toc import Toc +from zero_to_one_hundred.tests.conftest import str_relaxed def test_init(get_config_map, persist_fs, process_fs, http_url): actual = Toc( - SBConfigMap(persist_fs), + get_config_map, persist_fs, process_fs, [], ) assert len(actual.meta_books) == 0 mb = MetaBook( - SBConfigMap(persist_fs), + get_config_map, persist_fs, process_fs, http_url, ) actual = Toc( - SBConfigMap(persist_fs), + get_config_map, persist_fs, process_fs, [mb], ) assert str(actual.readme_md).endswith("toc.md") assert len(actual.meta_books) == 1 + + +def test_asMarkDown(get_config_map, persist_fs, process_fs, http_url, http_url2): + metabooks = [ + MetaBook( + get_config_map, + persist_fs, + process_fs, + http_url, + ), + MetaBook( + get_config_map, + persist_fs, + process_fs, + http_url2, + ), + ] + actual = Toc( + get_config_map, + persist_fs, + process_fs, + [], + ) + current = actual.asMarkDown() + expected = """ +# TOC +## `0` books +### 2099/01/01 - 00:00:00 +| ISBN | img | epub | pdf | `json-contents` | `status` | +|--- |--- |--- |--- |--- |--- | + """ + assert str_relaxed("".join(current)) == str_relaxed("".join(expected))