Initial Commit: Status Testing
CI / audit (push) Skipped
CI / checks (push) Failing after 37s
CI / image (push) Skipped

This commit is contained in:
marco.morath committed 2026-11-25 18:46:04 +01:00
1 parent 1eff675f05
commit 42dd1f2d4a
286 files changed
+64800 -369

No files matched your search

+64
View File
@@ -0,0 +1,64 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
"""Eigenes Logo: neu berechnet, drei Fassungen, nur bekannte Dateien (ohne Datenbank)."""
from __future__ import annotations
from pathlib import Path
import pytest
pytest.importorskip("PIL")
from PIL import Image, ImageDraw
from surveybox import branding
from surveybox.media import images
def logo_file(tmp_path: Path, size: tuple[int, int] = (1200, 300)) -> Path:
img = Image.new("RGBA", size, (0, 0, 0, 0))
ImageDraw.Draw(img).rectangle((100, 50, size[0] - 100, size[1] - 50), fill=(200, 30, 30, 255))
path = tmp_path / "in.png"
img.save(path)
return path
def test_default_until_a_logo_is_saved(tmp_path: Path) -> None:
assert branding.current(tmp_path) == branding.DEFAULT
assert branding.DEFAULT.url("logo") is None
brand = branding.save_logo(tmp_path, logo_file(tmp_path))
assert brand.custom and brand.url("favicon") == f"/branding/favicon.png?v={brand.version}"
sizes = {name: Image.open(tmp_path / "branding" / name).size
for name in branding.FILES.values() if name != "logo-dark.png"}
assert not brand.dark and brand.url("logo_dark") is None
assert sizes["favicon.png"] == (64, 64) and sizes["touch.png"] == (180, 180)
assert sizes["logo.png"][0] <= 800 and sizes["logo.png"][1] <= 240
# Leere Ränder sind abgeschnitten
width, height = sizes["logo.png"]
assert width == 800 and 158 <= height <= 162
branding.remove_logo(tmp_path)
assert branding.current(tmp_path) == branding.DEFAULT
def test_only_known_files_are_served(tmp_path: Path) -> None:
branding.save_logo(tmp_path, logo_file(tmp_path))
assert branding.file_path(tmp_path, "logo.png") is not None
assert branding.file_path(tmp_path, "branding.json") is None
assert branding.file_path(tmp_path, "../secret") is None
def test_svg_and_garbage_are_refused(tmp_path: Path) -> None:
svg = tmp_path / "x.svg"
svg.write_text('<svg xmlns="http://www.w3.org/2000/svg"><script>alert(1)</script></svg>')
with pytest.raises(images.ImageError):
branding.save_logo(tmp_path, svg)
assert branding.current(tmp_path) == branding.DEFAULT
def test_dark_logo(tmp_path: Path) -> None:
branding.save_logo(tmp_path, logo_file(tmp_path))
brand = branding.save_logo(tmp_path, logo_file(tmp_path), dark=True)
assert brand.dark and brand.url("logo_dark") == f"/branding/logo-dark.png?v={brand.version}"
branding.remove_dark_logo(tmp_path)
brand = branding.current(tmp_path)
assert brand.custom and not brand.dark