Files
flexly-cms/tests/test_packaging.py
phelex 0d171915d7 Add Site Studio themes and Theme Manager
Support categorized fragments, theme presets, block widths, and server-backed theme editing with onboarding and preview.

Include Site Studio, design sources, specification and verification reports; remove the legacy studio-site example.
2026-11-13 14:04:49 +03:00

67 lines
4.0 KiB
Python

"""Регрессия: в установленный пакет (Docker-образ, wheel) должны попасть шаблоны и статика админки,
встроенные фрагменты и стили. Раньше package-data включал только builtin/."""
import fnmatch
import glob
import shutil
import subprocess
import sys
import tempfile
import tomllib
import unittest
import zipfile
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
PKG = ROOT / "src" / "site_engine"
class PackagingTest(unittest.TestCase):
def test_package_data_patterns_cover_every_runtime_file(self):
patterns = tomllib.loads((ROOT / "pyproject.toml").read_text(encoding="utf-8"))["tool"]["setuptools"]["package-data"]["site_engine"]
runtime = [p for sub in ("builtin", "web/admin/templates", "web/admin/static") for p in (PKG / sub).rglob("*")
if p.is_file() and p.suffix != ".pyc" and "__pycache__" not in p.parts]
self.assertGreater(len(runtime), 50)
uncovered = [str(p.relative_to(PKG)) for p in runtime
if not any(fnmatch.fnmatch(p.relative_to(PKG).as_posix(), pat.replace("**/*", "*")) for pat in patterns)]
self.assertEqual(uncovered, [])
def test_built_wheel_contains_templates_static_and_fragments(self):
try:
import setuptools # noqa: F401
except ImportError:
self.skipTest("нет setuptools")
before = {name: (ROOT / name).exists() for name in ("build", "src/site_engine.egg-info")}
with tempfile.TemporaryDirectory() as tmp:
project = Path(tmp) / "project"
shutil.copytree(ROOT, project, ignore=shutil.ignore_patterns(
"build", "*.egg-info", "__pycache__", ".git", "tests", "docs", "examples", "dist", ".engine"))
result = subprocess.run([sys.executable, "-m", "pip", "wheel", str(project), "--no-deps", "--no-build-isolation",
"-q", "-w", str(Path(tmp) / "out")], check=False, capture_output=True, text=True, timeout=180)
wheels = glob.glob(f"{tmp}/out/*.whl")
if result.returncode != 0 or not wheels:
self.skipTest(f"wheel не собрался в этом окружении: {result.stderr[-200:]}")
names = zipfile.ZipFile(wheels[0]).namelist()
after = {name: (ROOT / name).exists() for name in before}
self.assertEqual(after, before, "сборка wheel не должна оставлять мусор в рабочем каталоге")
for needed in ("site_engine/web/admin/templates/login.html.j2", "site_engine/web/admin/templates/page_edit.html.j2",
"site_engine/web/admin/static/admin.css", "site_engine/web/admin/static/htmx.min.js",
"site_engine/web/admin/static/VENDOR.md", "site_engine/web/admin/static/admin.js",
"site_engine/web/admin/static/editor.js", "site_engine/web/admin/static/preview.js",
"site_engine/web/admin/templates/document.html.j2", "site_engine/web/admin/templates/editor_result.html.j2",
"site_engine/web/admin/templates/preview_result.html.j2", "site_engine/builtin/base.css",
"site_engine/builtin/fragments/marketing/hero/template.html.j2",
"site_engine/builtin/containers.css", "site_engine/builtin/themes/v1/fonts.json",
*(f"site_engine/builtin/themes/v1/{name}.json" for name in ("minimal", "dark", "editorial", "bold", "natural", "custom"))):
self.assertIn(needed, names)
fragment_files = {
"site_engine/" + p.relative_to(PKG).as_posix()
for p in (PKG / "builtin/fragments").rglob("*")
if p.is_file() and p.suffix != ".pyc" and "__pycache__" not in p.parts
}
self.assertTrue(fragment_files.issubset(names), sorted(fragment_files - set(names)))
if __name__ == "__main__":
unittest.main()