Fuehre die Pflicht-Suite nach dem Dev-Deploy gegen tsumugu_test auf der bestehenden Dev-Postgres aus.
Deploy Development / deploy (push) Failing after 20s
Test Suite / pytest-backend (push) Failing after 35s
Test Suite / smoke-dev (push) Failing after 0s
Test Suite / frontend-build (push) Successful in 7s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-10-17 07:21:20 +02:00
1 parent b328385561
commit 0924e28fce
8 files changed
+125 -88

No files matched your search

+20 -31
View File
@@ -1,4 +1,8 @@
"""Ephemeral database for the mandatory suite. Dev and prod databases are refused."""
"""Suite on the existing Dev Postgres, database tsumugu_test.
Dev and prod databases are refused. The workflow drops and recreates
tsumugu_test beside tsumugu_dev. This is not a third server.
"""
from __future__ import annotations
@@ -8,33 +12,21 @@ import tempfile
import psycopg
import pytest
TEST_DB = "tsumugu_pytest"
FORBIDDEN = {"tsumugu", "tsumugu_dev"}
FORBIDDEN = frozenset({"tsumugu", "tsumugu_dev", "postgres", "template0", "template1"})
if os.environ.get("TSUMUGU_TEST_DB") in FORBIDDEN or os.environ.get("DB_NAME") in FORBIDDEN:
raise RuntimeError("Die Test-Suite darf nicht gegen Dev- oder Prod-Datenbanken laufen.")
_name = os.environ.get("DB_NAME", "").strip().lower()
if not _name.endswith("_test") or _name in FORBIDDEN:
raise RuntimeError(
"DB_NAME fehlt oder ist gesperrt. Die Suite nutzt auf der Dev-Postgres "
"die Datenbank tsumugu_test, nicht tsumugu oder tsumugu_dev."
)
os.environ["TSUMUGU_ENV"] = "development"
os.environ["DB_HOST"] = os.environ.get("TSUMUGU_TEST_HOST", "127.0.0.1")
os.environ["DB_PORT"] = os.environ.get("TSUMUGU_TEST_PORT", "5432")
os.environ["DB_NAME"] = TEST_DB
os.environ["DB_USER"] = os.environ.get("TSUMUGU_TEST_USER", "tsumugu")
os.environ["DB_PASSWORD"] = os.environ.get("TSUMUGU_TEST_PASSWORD", "pytest")
os.environ["ALLOWED_ORIGINS"] = "http://testserver"
os.environ["SEED_DEMO"] = "false"
os.environ["MEDIA_ROOT"] = tempfile.mkdtemp(prefix="tsumugu-pytest-")
def _admin_dsn() -> str:
admin_db = os.environ.get("TSUMUGU_TEST_ADMIN_DB", "postgres")
if admin_db in FORBIDDEN or admin_db == TEST_DB:
raise RuntimeError("Die Verwaltungsverbindung der Test-Suite darf nicht die Fachdatenbank sein.")
return (
f"host={os.environ['DB_HOST']} port={os.environ['DB_PORT']} dbname={admin_db} "
f"user={os.environ['DB_USER']} password={os.environ['DB_PASSWORD']} connect_timeout=5"
)
def _reset(settings) -> None:
with psycopg.connect(settings.dsn(), autocommit=True) as conn:
conn.execute(
@@ -51,24 +43,21 @@ def _reset(settings) -> None:
@pytest.fixture(scope="session")
def database():
if os.environ["DB_NAME"] in FORBIDDEN:
raise RuntimeError("Die Test-Suite darf nicht gegen Dev- oder Prod-Datenbanken laufen.")
try:
admin = psycopg.connect(_admin_dsn(), autocommit=True)
except psycopg.OperationalError as exc:
pytest.fail(f"Die Test-Suite braucht ein kurzlebiges PostgreSQL. {exc}")
admin.execute(f"DROP DATABASE IF EXISTS {TEST_DB} WITH (FORCE)")
admin.execute(f"CREATE DATABASE {TEST_DB}")
name = os.environ.get("DB_NAME", "").strip().lower()
if name in FORBIDDEN or not name.endswith("_test"):
pytest.fail(
"DB_NAME muss auf der Dev-Postgres eine Datenbank *_test sein, "
"nicht tsumugu oder tsumugu_dev."
)
from app.core.settings import get_settings
from app.db.migrate import migrate
get_settings.cache_clear()
settings = get_settings()
assert settings.db_name == TEST_DB
if settings.db_name.lower() in FORBIDDEN or not settings.db_name.lower().endswith("_test"):
pytest.fail("Die Test-Suite darf nicht gegen Dev- oder Prod-Datenbanken laufen.")
migrate(settings)
yield settings
admin.execute(f"DROP DATABASE IF EXISTS {TEST_DB} WITH (FORCE)")
admin.close()
@pytest.fixture(scope="session")
+4 -4
View File
@@ -13,14 +13,14 @@ from app.core.settings import Settings
from app.entrypoint import prepare
from app.fixtures import purge_fixture_data
from app.ops import create_case
from app.seed import ADA_EMAIL, BEN_EMAIL, seed_demo
from tests.conftest import FORBIDDEN, TEST_DB
from app.seed import ADA_EMAIL, BEN_EMAIL, is_test_database, seed_demo
from tests.conftest import FORBIDDEN
from tests.support import PASSWORD
def test_database_is_ephemeral(database):
assert database.db_name == TEST_DB
assert database.db_name not in FORBIDDEN
assert is_test_database(database.db_name)
assert database.db_name.lower() not in FORBIDDEN
assert database.tsumugu_env == "development"