From e6d80034ba7fc89b8016a3115b138c581d7b153d Mon Sep 17 00:00:00 2001 From: renaud gaudin Date: Mon, 29 Jun 2020 22:30:18 +0000 Subject: [PATCH] fixed redirect_url accessor `lib.cxx` mirrors libzim's `getRedirectUrl()` with `get_redirect_url()`. That methods had incorrectly been named `redirect_url`. --- libzim/writer.py | 4 ++-- tests/test_libzim.py | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/libzim/writer.py b/libzim/writer.py index 7a7d1ce7..02074b04 100644 --- a/libzim/writer.py +++ b/libzim/writer.py @@ -76,9 +76,9 @@ def should_index(self) -> bool: """ Whether the article's content should be indexed or not """ raise NotImplementedError("should_index must be implemented.") - def redirect_url(self) -> str: + def get_redirect_url(self) -> str: """ Full URL including namespace of another article """ - raise NotImplementedError("redirect_url must be implemented.") + raise NotImplementedError("get_redirect_url must be implemented.") def _get_data(self) -> Blob: """ Internal data-retrieval with a cache to the content's pointer diff --git a/tests/test_libzim.py b/tests/test_libzim.py index ab2d1d50..06695475 100644 --- a/tests/test_libzim.py +++ b/tests/test_libzim.py @@ -253,3 +253,24 @@ def get_data(self): py = subprocess.run([sys.executable, "-c", pycode]) assert py.returncode == 0 assert not path.exists() + + +def test_redirect_url(tmpdir): + url = "A/welcome" + redirect_url = "A/home" + + class RedirectArticle(SimpleArticle): + def is_redirect(self): + return True + + def get_redirect_url(self): + return url + + path = tmpdir / "test.zim" + with Creator(path, "welcome") as zim_creator: + zim_creator.add_article(SimpleArticle(title="Hello", mime_type="text/html", content="", url=url)) + zim_creator.add_article(RedirectArticle(content="", title="", mime_type="", url=redirect_url)) + + with File(path) as reader: + assert reader.get_article(redirect_url).is_redirect + assert reader.get_article(redirect_url).get_redirect_article().longurl == url