hugin/server/tests/test_package.py
2026-10-27 08:33:21 +01:00

46 lines
1.5 KiB
Python

import pytest
from conftest import EXAMPLES, example
from hugin_core.package import Kind, PackageError, load
def test_load_reads_manifest_and_files():
package = example("pub-munin-nutzen/1.4.0")
assert package.manifest.kind == Kind.SKILL
assert sorted(package.files) == ["SKILL.md", "referenz/beispiele.md"]
assert package.content.startswith("# Munin nutzen")
assert list(package.helper_files) == ["referenz/beispiele.md"]
def test_description_without_line_breaks():
text = example("pub-munin-nutzen/1.4.0").manifest.description_text
assert "\n" not in text and text.endswith("arbeitest.")
def test_checksum_stable_and_content_dependent():
a = example("pub-munin-nutzen/1.4.0")
assert a.checksum() == example("pub-munin-nutzen/1.4.0").checksum()
assert a.checksum() != example("pub-munin-nutzen/1.5.0").checksum()
def test_unknown_field_in_manifest(tmp_path):
(tmp_path / "hugin.yaml").write_text(
"id: pub-x\nkind: skill\nversion: 1.0.0\nowner: p\nscope: public\n"
"description: x\nfarbe: blau\n"
)
with pytest.raises(PackageError, match="farbe"):
load(tmp_path)
def test_without_manifest(tmp_path):
with pytest.raises(PackageError, match="fehlt"):
load(tmp_path)
def test_symlink_rejected(tmp_path):
folder = tmp_path / "p"
folder.mkdir()
(folder / "hugin.yaml").write_text((EXAMPLES / "packages/pub-hausregeln/1.0.0/hugin.yaml").read_text())
(folder / "RULES.md").symlink_to("/etc/hosts")
with pytest.raises(PackageError, match="Symlink"):
load(folder)