- Updated form template to prefill currency input with default value and added help text for clarity. - Modified integration tests to assert more descriptive error messages for invalid currency codes. - Introduced new tests for currency normalization and validation in various scenarios, including imports and exports. - Added comprehensive tests for pricing calculations, ensuring defaults are respected and overrides function correctly. - Implemented unit tests for pricing settings repository, ensuring CRUD operations and default settings are handled properly. - Enhanced scenario pricing evaluation tests to validate currency handling and metadata defaults. - Added simulation tests to ensure Monte Carlo runs are accurate and handle various distribution scenarios.
88 lines
3.0 KiB
Python
88 lines
3.0 KiB
Python
import logging
|
|
from typing import Awaitable, Callable
|
|
|
|
from fastapi import FastAPI, Request, Response
|
|
from fastapi.staticfiles import StaticFiles
|
|
|
|
from config.database import Base, engine
|
|
from config.settings import get_settings
|
|
from middleware.auth_session import AuthSessionMiddleware
|
|
from middleware.validation import validate_json
|
|
from models import (
|
|
FinancialInput,
|
|
Project,
|
|
Scenario,
|
|
SimulationParameter,
|
|
)
|
|
from routes.auth import router as auth_router
|
|
from routes.dashboard import router as dashboard_router
|
|
from routes.imports import router as imports_router
|
|
from routes.exports import router as exports_router
|
|
from routes.projects import router as projects_router
|
|
from routes.reports import router as reports_router
|
|
from routes.scenarios import router as scenarios_router
|
|
from monitoring import router as monitoring_router
|
|
from services.bootstrap import bootstrap_admin, bootstrap_pricing_settings
|
|
|
|
# Initialize database schema (imports above ensure models are registered)
|
|
Base.metadata.create_all(bind=engine)
|
|
|
|
app = FastAPI()
|
|
|
|
app.add_middleware(AuthSessionMiddleware)
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
@app.middleware("http")
|
|
async def json_validation(
|
|
request: Request, call_next: Callable[[Request], Awaitable[Response]]
|
|
) -> Response:
|
|
return await validate_json(request, call_next)
|
|
|
|
|
|
@app.get("/health", summary="Container health probe")
|
|
async def health() -> dict[str, str]:
|
|
return {"status": "ok"}
|
|
|
|
|
|
@app.on_event("startup")
|
|
async def ensure_admin_bootstrap() -> None:
|
|
settings = get_settings()
|
|
admin_settings = settings.admin_bootstrap_settings()
|
|
pricing_metadata = settings.pricing_metadata()
|
|
try:
|
|
role_result, admin_result = bootstrap_admin(settings=admin_settings)
|
|
pricing_result = bootstrap_pricing_settings(metadata=pricing_metadata)
|
|
logger.info(
|
|
"Admin bootstrap completed: roles=%s created=%s updated=%s rotated=%s assigned=%s",
|
|
role_result.ensured,
|
|
admin_result.created_user,
|
|
admin_result.updated_user,
|
|
admin_result.password_rotated,
|
|
admin_result.roles_granted,
|
|
)
|
|
logger.info(
|
|
"Pricing settings bootstrap completed: slug=%s created=%s updated_fields=%s impurity_upserts=%s projects_assigned=%s",
|
|
pricing_result.seed.settings.slug,
|
|
pricing_result.seed.created,
|
|
pricing_result.seed.updated_fields,
|
|
pricing_result.seed.impurity_upserts,
|
|
pricing_result.projects_assigned,
|
|
)
|
|
except Exception: # pragma: no cover - defensive logging
|
|
logger.exception(
|
|
"Failed to bootstrap administrator or pricing settings")
|
|
|
|
|
|
app.include_router(dashboard_router)
|
|
app.include_router(auth_router)
|
|
app.include_router(imports_router)
|
|
app.include_router(exports_router)
|
|
app.include_router(projects_router)
|
|
app.include_router(scenarios_router)
|
|
app.include_router(reports_router)
|
|
app.include_router(monitoring_router)
|
|
|
|
app.mount("/static", StaticFiles(directory="static"), name="static")
|