feat: add SEED_ADMIN_EMAIL for Docker test environments

app/main.py: seed admin user on startup when SEED_ADMIN_EMAIL is set.
docker-compose.test.yml: expose port 8000, add seed env var.
This commit is contained in:
ZdenekSrotyr 2026-03-31 09:48:12 +02:00
parent 617e724d21
commit e1e2d6d903
2 changed files with 21 additions and 15 deletions

View file

@ -58,6 +58,22 @@ def create_app() -> FastAPI:
except Exception as e:
logger.warning(f"Could not load instance config: {e}")
# Seed admin user for testing/CI (when SEED_ADMIN_EMAIL is set)
seed_email = os.environ.get("SEED_ADMIN_EMAIL")
if seed_email:
try:
from src.db import get_system_db
from src.repositories.users import UserRepository
conn = get_system_db()
repo = UserRepository(conn)
if not repo.get_by_email(seed_email):
import uuid
repo.create(id=str(uuid.uuid4()), email=seed_email, name="Admin", role="admin")
logger.info("Seeded admin user: %s", seed_email)
conn.close()
except Exception as e:
logger.warning(f"Could not seed admin: {e}")
# Static files
static_dir = Path(__file__).parent / "web" / "static"
if static_dir.exists():

View file

@ -2,30 +2,20 @@ services:
app:
build: .
command: uvicorn app.main:app --host 0.0.0.0 --port 8000
ports:
- "8000:8000"
environment:
- DATA_DIR=/data
- JWT_SECRET_KEY=test-secret-for-ci
- JWT_SECRET_KEY=test-secret-for-ci-32chars!!!
- TESTING=true
- SEED_ADMIN_EMAIL=admin@test.com
volumes:
- test-data:/data
healthcheck:
test: ["CMD", "python", "-c", "import httpx; r=httpx.get('http://localhost:8000/api/health'); exit(0 if r.status_code==200 else 1)"]
interval: 5s
timeout: 3s
retries: 10
test-runner:
build: .
command: python -m pytest tests/test_db.py tests/test_repositories.py tests/test_migration.py tests/test_api.py -v
environment:
- DATA_DIR=/data
- JWT_SECRET_KEY=test-secret-for-ci
- API_URL=http://app:8000
volumes:
- test-data:/data
depends_on:
app:
condition: service_healthy
retries: 15
volumes:
test-data: