Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix download link for binary content (missing namespace) #1854

Merged
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
51 changes: 51 additions & 0 deletions src/moin/converters/_tests/test_everything.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright: 2025 MoinMoin
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.

"""
MoinMoin - Tests for moin.converters.everything
"""

import pytest

from . import serialize, XMLNS_RE

from moin.constants.keys import CONTENTTYPE, ITEMTYPE, REV_NUMBER
from moin.converters.everything import Converter
from moin.items.content import Content

from moin.utils.interwiki import split_fqname

from moin.items import Item
from moin.utils.tree import moin_page, xlink, html, xinclude

from unittest.mock import Mock

namespaces = {moin_page: "", xlink: "xlink", html: "xhtml", xinclude: "xinclude"}

meta = {CONTENTTYPE: "binary/blob", ITEMTYPE: "default", REV_NUMBER: 1}

output_re = XMLNS_RE


def serialize_strip(elem, **options):
result = serialize(elem, namespaces=namespaces, **options)
return output_re.sub("", result)


@pytest.mark.parametrize(
"input,output",
[
(
"machines/nuc/fw2.blob",
'<page><body><a xlink:href="wiki:///machines/nuc/fw2.blob?do=get&amp;rev=691da3aa1dd146d296bcd9ac92b25be5">Download machines/nuc/fw2.blob.</a></body></page>',
)
],
)
def test_conv(input, output):
rev = Mock()
rev.meta = meta
rev.revid = "691da3aa1dd146d296bcd9ac92b25be5"
rev.item = Item(split_fqname(input), rev=rev, content=Content.create(meta[CONTENTTYPE]))
conv = Converter()
out = conv(rev, rev.item.contenttype)
assert serialize_strip(out) == output
4 changes: 2 additions & 2 deletions src/moin/converters/everything.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def _factory(cls, input, output, **kw):

def __call__(self, rev, contenttype=None, arguments=None):
try:
item_name = rev.item.name or rev.meta["name"][0]
item_name = rev.item.fqname.fullname or rev.meta["name"][0]
except IndexError:
# item is deleted
message = _(
Expand All @@ -37,7 +37,7 @@ def __call__(self, rev, contenttype=None, arguments=None):
body = moin_page.body(children=(admonition,))
return moin_page.page(children=(body,))
attrib = {xlink.href: Iri(scheme="wiki", authority="", path="/" + item_name, query=f"do=get&rev={rev.revid}")}
a = moin_page.a(attrib=attrib, children=[f"Download {item_name}."])
a = moin_page.a(attrib=attrib, children=[_("Download {item_name}.").format(item_name=item_name)])
body = moin_page.body(children=(a,))
return moin_page.page(children=(body,))

Expand Down