Enhance UI rendering and add unit tests for simulation functionality

- Updated the `_render` function in `ui.py` to correctly pass the request object to `TemplateResponse`.
- Initialized `upcoming_maintenance` as a typed list in `_load_dashboard` for better type safety.
- Added new unit tests in `test_simulation.py` to cover triangular sampling and uniform distribution defaults.
- Implemented a test to ensure that running the simulation without parameters returns an empty result.
- Created a parameterized test in `test_ui_routes.py` to verify that additional UI routes render the correct templates and context.
This commit is contained in:
2025-10-21 09:26:39 +02:00
parent 9114b584c2
commit 139ae04538
6 changed files with 2319 additions and 8 deletions

View File

@@ -40,7 +40,8 @@ def _render(
template_name: str,
extra: Optional[Dict[str, Any]] = None,
):
return templates.TemplateResponse(template_name, _context(request, extra))
context = _context(request, extra)
return templates.TemplateResponse(request, template_name, context)
def _format_currency(value: float) -> str:
@@ -436,7 +437,7 @@ def _load_dashboard(db: Session) -> Dict[str, Any]:
recent_simulations.sort(key=lambda item: item["iterations"], reverse=True)
recent_simulations = recent_simulations[:5]
upcoming_maintenance = []
upcoming_maintenance: list[Dict[str, Any]] = []
for record in (
db.query(Maintenance)
.order_by(Maintenance.maintenance_date.asc())