feat: add integration tests for project and scenario lifecycles, update templates to new Starlette signature, and optimize project retrieval logic

This commit is contained in:
2025-11-09 19:47:35 +01:00
parent dad862e48e
commit 2d848c2e09
10 changed files with 292 additions and 72 deletions

View File

@@ -105,10 +105,9 @@ def dashboard_home(
uow: UnitOfWork = Depends(get_unit_of_work),
) -> HTMLResponse:
context = {
"request": request,
"metrics": _load_metrics(uow),
"recent_projects": _load_recent_projects(uow),
"simulation_updates": _load_simulation_updates(uow),
"scenario_alerts": _load_scenario_alerts(request, uow),
}
return templates.TemplateResponse("dashboard.html", context)
return templates.TemplateResponse(request, "dashboard.html", context)

View File

@@ -59,9 +59,9 @@ def project_list_page(
for project in projects:
setattr(project, "scenario_count", len(project.scenarios))
return templates.TemplateResponse(
request,
"projects/list.html",
{
"request": request,
"projects": projects,
},
)
@@ -75,9 +75,9 @@ def project_list_page(
)
def create_project_form(request: Request) -> HTMLResponse:
return templates.TemplateResponse(
request,
"projects/form.html",
{
"request": request,
"project": None,
"operation_types": _operation_type_choices(),
"form_action": request.url_for("projects.create_project_submit"),
@@ -109,9 +109,9 @@ def create_project_submit(
op_type = MiningOperationType(operation_type)
except ValueError as exc:
return templates.TemplateResponse(
request,
"projects/form.html",
{
"request": request,
"project": None,
"operation_types": _operation_type_choices(),
"form_action": request.url_for("projects.create_project_submit"),
@@ -131,9 +131,9 @@ def create_project_submit(
uow.projects.create(project)
except EntityConflictError as exc:
return templates.TemplateResponse(
request,
"projects/form.html",
{
"request": request,
"project": project,
"operation_types": _operation_type_choices(),
"form_action": request.url_for("projects.create_project_submit"),
@@ -219,9 +219,9 @@ def view_project(
),
}
return templates.TemplateResponse(
request,
"projects/detail.html",
{
"request": request,
"project": project,
"scenarios": scenarios,
"scenario_stats": scenario_stats,
@@ -246,9 +246,9 @@ def edit_project_form(
) from exc
return templates.TemplateResponse(
request,
"projects/form.html",
{
"request": request,
"project": project,
"operation_types": _operation_type_choices(),
"form_action": request.url_for(
@@ -295,9 +295,9 @@ def edit_project_submit(
project.operation_type = MiningOperationType(operation_type)
except ValueError as exc:
return templates.TemplateResponse(
request,
"projects/form.html",
{
"request": request,
"project": project,
"operation_types": _operation_type_choices(),
"form_action": request.url_for(

View File

@@ -218,9 +218,9 @@ def create_scenario_form(
) from exc
return templates.TemplateResponse(
request,
"scenarios/form.html",
{
"request": request,
"project": project,
"scenario": None,
"scenario_statuses": _scenario_status_choices(),
@@ -291,9 +291,9 @@ def create_scenario_submit(
uow.scenarios.create(scenario)
except EntityConflictError as exc:
return templates.TemplateResponse(
request,
"scenarios/form.html",
{
"request": request,
"project": project,
"scenario": scenario,
"scenario_statuses": _scenario_status_choices(),
@@ -347,9 +347,9 @@ def view_scenario(
}
return templates.TemplateResponse(
request,
"scenarios/detail.html",
{
"request": request,
"project": project,
"scenario": scenario,
"scenario_metrics": scenario_metrics,
@@ -378,9 +378,9 @@ def edit_scenario_form(
project = uow.projects.get(scenario.project_id)
return templates.TemplateResponse(
request,
"scenarios/form.html",
{
"request": request,
"project": project,
"scenario": scenario,
"scenario_statuses": _scenario_status_choices(),