platform/control-panel/tests/test_config.py
Bart Van Geyt fe4cbbe36a Phase 4: provisioning CLI (heleosctl)
Python control-panel package driving the full provisioning flow from a
site's site.yaml (docs/05):

- provision: ZFS web dataset + ownership, per-site DB + least-priv user,
  generated .env encrypted to secrets.enc.yaml (SOPS/age), render the
  profile templates + persist site.yaml, per-customer chrooted SFTP
  account, docker compose up.
- deprovision (gated: data destroyed only with --purge, after a final
  backup), backup (ZFS snapshot + mariadb-dump), restore (rollback +
  import), render (preview), list.

Design: one command/file runner with a real --dry-run (prints every
action, redacts secrets); idempotent steps; Config + Site validation
mirroring docs/03; passwords never logged.

Modules: cli, config, naming, context, render, runner, zfs, database,
secrets, sftp, compose, provision, backup. Plus pyproject (heleosctl
entry point), config.example.yaml, an example site, and a README.

Tests: 22 pure-logic unit tests (naming, config validation, template
render across all profiles + db on/off) — all passing. Full provision and
deprovision verified end-to-end in --dry-run.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-07 17:18:36 +02:00

34 lines
1.2 KiB
Python

import pytest
from heleos.config import Site
from heleos.errors import ValidationError
def test_wordpress_forces_database():
s = Site.from_dict({"customer": "acme", "site": "blog", "profile": "wordpress",
"domains": ["blog.acme.com"], "database": False})
assert s.database is True
def test_redirect_requires_target():
with pytest.raises(ValidationError):
Site.from_dict({"customer": "acme", "site": "old", "profile": "redirect",
"domains": ["old.acme.com"]})
def test_redirect_needs_source_domain():
with pytest.raises(ValidationError):
Site.from_dict({"customer": "acme", "site": "old", "profile": "redirect",
"domains": [], "redirect_to": "https://acme.com"})
def test_static_cannot_have_database():
with pytest.raises(ValidationError):
Site.from_dict({"customer": "acme", "site": "site", "profile": "static",
"domains": ["acme.com"], "database": True})
def test_unknown_profile_rejected():
with pytest.raises(ValidationError):
Site.from_dict({"customer": "acme", "site": "x", "profile": "django",
"domains": ["acme.com"]})