Files
xenia-pos-cloud/cloud_backend/tests/conftest.py
T
bonaminandClaude Opus 5.5 48fd10df77 feat(cloud): Alembic, license token v2 with modules, plan presets, module editor
Platform v2 step 1.7 (APPS_PLATFORM D-3, D-20, D-21, D-22, §5.2).
- Alembic replaces create_all + _run_migrations. 0001_cloud_baseline is
  exactly the v1 production schema (incl. the dead menu_hours_en/_gr), checked
  against a frozen fixture; schema.py refuses an unstamped v1 DB, so prod is
  stamped once at cutover (DEPLOYMENT_GUIDE Part 6)
- 0002_v2_licensing: sites.modules (JSON), sites.module_catalog(_at),
  plan_presets; existing sites get every module v1 had (KDS unlimited); the
  same map is seeded as preset "Everything (v1 sites)"; dead columns dropped
- license token v: 2 with a normalized `modules` map
- heartbeat v2: request {version, local_ip, module_catalog} (catalogue stored
  per site); response {license_token, latest_version, waiter_domain,
  site_numeric_id} - the unsigned v1 license fields are gone
- sites API: create with a preset, PUT /{id}/modules (validated),
  POST /{id}/apply-preset/{preset}; /api/presets CRUD
- sysadmin panel: Licensed modules card per site (built from the reported
  catalogue, fallback list), preset picker on register, Presets page
- .dockerignore: local *.db, .env and tests no longer baked into the image
- tests (new): baseline = v1, unstamped refused, stamp+upgrade of a v1 DB,
  drift, token v2 shape/signature, module edits, presets; CL-2/CL-7 rules

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 19:27:47 +02:00

44 lines
1.6 KiB
Python

"""Cloud backend tests. Run from cloud_backend/: python -m pytest tests -q
Before anything imports config/database, DATABASE_URL points at a fresh temp file and a
throwaway LICENSE_SIGNING_KEY is set, so tests never touch a real cloud DB or key.
"""
import base64
import os
import sys
import tempfile
from pathlib import Path
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey
_TMP = Path(tempfile.mkdtemp(prefix="xenia-cloud-tests-"))
os.environ["DATABASE_URL"] = f"sqlite:///{(_TMP / 'cloud.db').as_posix()}"
TEST_KEY = Ed25519PrivateKey.generate()
os.environ["LICENSE_SIGNING_KEY"] = base64.b64encode(
TEST_KEY.private_bytes(serialization.Encoding.Raw, serialization.PrivateFormat.Raw,
serialization.NoEncryption())).decode()
TEST_PUB = base64.b64encode(TEST_KEY.public_key().public_bytes(
serialization.Encoding.Raw, serialization.PublicFormat.Raw)).decode()
os.environ["ADMIN_USERNAME"] = "sysadmin"
os.environ["ADMIN_PASSWORD"] = "test-admin-pw"
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
import pytest # noqa: E402
@pytest.fixture(scope="session")
def client():
from fastapi.testclient import TestClient
import main
with TestClient(main.app) as c: # runs the lifespan: Alembic upgrade + default admin
yield c
@pytest.fixture(scope="session")
def admin_h(client):
r = client.post("/api/auth/login", json={"username": "sysadmin", "password": "test-admin-pw"})
assert r.status_code == 200, r.text
return {"Authorization": f"Bearer {r.json()['access_token']}"}