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

46 lines
1.8 KiB
Python

"""CLI zum Herunterladen und Versionsangaben (→ KONZEPT.md 18)."""
import hashlib
import pytest
from fastapi.testclient import TestClient
from hugin_app.app import create_app
from hugin_app.settings import Settings
from hugin_app.hugin import Hugin
from hugin_app.migration import migrate
from test_app import Env
@pytest.fixture
def with_downloads(tmp_path, database_url):
folder = tmp_path / "downloads"
for version in ("0.1.0", "0.2.0", "kaputt"):
(folder / version).mkdir(parents=True)
content = b"programm"
(folder / "0.2.0" / "hugin-linux-amd64").write_bytes(content)
(folder / "0.2.0" / "hugin-windows-amd64.exe").write_bytes(content)
(folder / "0.2.0" / "notizen.txt").write_text("nicht anbieten")
(folder / "0.2.0" / "SHA256SUMS").write_text(f"{hashlib.sha256(content).hexdigest()} hugin-linux-amd64\n")
url = database_url
migrate(url)
hugin = Hugin(Settings(database_url=url, admin_token="admin-geheim", download_folder=str(folder),
cli_min_version="0.2.0"))
return Env(TestClient(create_app(hugin)), hugin)
def test_configuration_names_cli(with_downloads):
k = with_downloads.client.get("/api/v1/config", headers=with_downloads.h("shop-lesen")).json()
assert k["cli"] == {"min_version": "0.2.0", "newest": "0.2.0"}
def test_download_page(with_downloads):
from test_web import browser
c = browser(with_downloads, "shop-lesen")
page = c.get("/download").text
assert "Version 0.2.0" in page and "hugin-windows-amd64.exe" in page and "notizen.txt" not in page
assert hashlib.sha256(b"programm").hexdigest() in page
assert c.get("/download/0.2.0/hugin-linux-amd64").content == b"programm"
for path in ("/download/0.2.0/notizen.txt", "/download/0.2.0/..%2F..%2Fhugin.db", "/download/../x/hugin-linux-amd64"):
assert c.get(path).status_code == 404