Kairo-Jinkendo/backend/tests/conftest.py
Lars 53047b6c16
All checks were successful
Deploy Development / deploy (push) Successful in 38s
Test Suite / pytest-backend (push) Successful in 18s
Test Suite / lint-backend (push) Successful in 1s
Test Suite / compose-smoke (push) Has been skipped
Test Suite / k6 /api/health Baseline (push) Successful in 18s
Test Suite / playwright-smoke (push) Successful in 24s
AP0.4: Feature-, Prompt- und Config-Registry mit Single-Render und Entitlements-Features.
Migration 005, Registry-Sync, Placeholder-Validation, capability-geschuetzte API, Tests und Abschlussbericht v0.1.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-04 23:29:02 +02:00

81 lines
2.1 KiB
Python

"""Shared pytest fixtures for AP0.2 auth tests."""
from __future__ import annotations
import os
import pytest
os.environ.setdefault("SKIP_DB_MIGRATE", "1")
os.environ.setdefault("SKIP_SEEDS", "1")
os.environ.setdefault("SKIP_BOOTSTRAP", "1")
os.environ.setdefault("SKIP_RIGHTS_SYNC", "1")
os.environ.setdefault("SKIP_REGISTRY_SYNC", "1")
def _db_available() -> bool:
try:
import psycopg2
conn = psycopg2.connect(
host=os.getenv("DB_HOST", "localhost"),
port=os.getenv("DB_PORT", "5432"),
dbname=os.getenv("DB_NAME", "kairo_dev"),
user=os.getenv("DB_USER", "kairo_dev"),
password=os.getenv("DB_PASSWORD", "dev_password"),
)
conn.close()
return True
except Exception:
return False
pytestmark = pytest.mark.skipif(not _db_available(), reason="PostgreSQL nicht erreichbar")
@pytest.fixture(scope="session", autouse=True)
def _run_migrations():
import run_migrations
assert run_migrations.main() == 0
@pytest.fixture(scope="session", autouse=True)
def _seed_hygiene():
"""Vor/nach Tests pytest-Artefakte aus der geteilten Dev-DB entfernen."""
import run_seeds
run_seeds.main(["--only", "seed_001_cleanup_pytest_artifacts"])
yield
run_seeds.main(["--only", "seed_001_cleanup_pytest_artifacts"])
@pytest.fixture(scope="session", autouse=True)
def _sync_rights_registry():
import rights_registrations # noqa: F401
from rights_registry import sync_rights_registry_to_db
assert sync_rights_registry_to_db() == 0
@pytest.fixture(scope="session", autouse=True)
def _sync_prompt_feature_config():
import feature_registrations # noqa: F401
import placeholder_registrations # noqa: F401
import prompt_registrations # noqa: F401
from sync_prompt_feature_config import main as sync_registries
assert sync_registries() == 0
@pytest.fixture()
def client():
import importlib
import main as main_module
importlib.reload(main_module)
from fastapi.testclient import TestClient
return TestClient(main_module.app)