Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions libzim/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions tests/test_libzim.py
Original file line number Diff line number Diff line change
Expand Up @@ -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