Skip to content

Commit 5cff1c5

Browse files
author
rgaudin
authored
fixed redirect_url accessor (#57)
`lib.cxx` mirrors libzim's `getRedirectUrl()` with `get_redirect_url()`. That methods had incorrectly been named `redirect_url`.
1 parent 3092492 commit 5cff1c5

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

libzim/writer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ def should_index(self) -> bool:
7676
""" Whether the article's content should be indexed or not """
7777
raise NotImplementedError("should_index must be implemented.")
7878

79-
def redirect_url(self) -> str:
79+
def get_redirect_url(self) -> str:
8080
""" Full URL including namespace of another article """
81-
raise NotImplementedError("redirect_url must be implemented.")
81+
raise NotImplementedError("get_redirect_url must be implemented.")
8282

8383
def _get_data(self) -> Blob:
8484
""" Internal data-retrieval with a cache to the content's pointer

tests/test_libzim.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,3 +253,24 @@ def get_data(self):
253253
py = subprocess.run([sys.executable, "-c", pycode])
254254
assert py.returncode == 0
255255
assert not path.exists()
256+
257+
258+
def test_redirect_url(tmpdir):
259+
url = "A/welcome"
260+
redirect_url = "A/home"
261+
262+
class RedirectArticle(SimpleArticle):
263+
def is_redirect(self):
264+
return True
265+
266+
def get_redirect_url(self):
267+
return url
268+
269+
path = tmpdir / "test.zim"
270+
with Creator(path, "welcome") as zim_creator:
271+
zim_creator.add_article(SimpleArticle(title="Hello", mime_type="text/html", content="", url=url))
272+
zim_creator.add_article(RedirectArticle(content="", title="", mime_type="", url=redirect_url))
273+
274+
with File(path) as reader:
275+
assert reader.get_article(redirect_url).is_redirect
276+
assert reader.get_article(redirect_url).get_redirect_article().longurl == url

0 commit comments

Comments
 (0)