Enhance testing framework and UI feedback
- Updated architecture documentation to include details on UI rendering checks and Playwright end-to-end tests. - Revised testing documentation to specify Playwright for frontend E2E tests and added details on running tests. - Implemented feedback mechanism in scenario form for successful creation notifications. - Added feedback div in ScenarioForm.html for user notifications. - Created new fixtures for Playwright tests to manage server and browser instances. - Developed comprehensive E2E tests for consumption, costs, equipment, maintenance, production, and scenarios. - Added smoke tests to verify UI page loading and form submissions. - Enhanced unit tests for simulation and validation, including new tests for report generation and validation errors. - Created new test files for router validation to ensure consistent error handling. - Established a new test suite for UI routes to validate dashboard and reporting functionalities. - Implemented validation tests to ensure proper handling of JSON payloads.
This commit is contained in:
@@ -4,6 +4,8 @@ import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from typing import Any, Dict, List
|
||||
|
||||
from models.simulation_result import SimulationResult
|
||||
from services.simulation import run_simulation
|
||||
|
||||
@@ -14,7 +16,7 @@ def client(api_client: TestClient) -> TestClient:
|
||||
|
||||
|
||||
def test_run_simulation_function_generates_samples():
|
||||
params = [
|
||||
params: List[Dict[str, Any]] = [
|
||||
{"name": "grade", "value": 1.8, "distribution": "normal", "std_dev": 0.2},
|
||||
{
|
||||
"name": "recovery",
|
||||
@@ -30,8 +32,73 @@ def test_run_simulation_function_generates_samples():
|
||||
assert results[0]["iteration"] == 1
|
||||
|
||||
|
||||
def test_run_simulation_with_zero_iterations_returns_empty():
|
||||
params: List[Dict[str, Any]] = [
|
||||
{"name": "grade", "value": 1.2, "distribution": "normal"}
|
||||
]
|
||||
results = run_simulation(params, iterations=0)
|
||||
assert results == []
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"parameter_payload,error_message",
|
||||
[
|
||||
({"name": "missing-value"}, "Parameter at index 0 must include 'value'"),
|
||||
(
|
||||
{
|
||||
"name": "bad-dist",
|
||||
"value": 1.0,
|
||||
"distribution": "unsupported",
|
||||
},
|
||||
"Parameter 'bad-dist' has unsupported distribution 'unsupported'",
|
||||
),
|
||||
(
|
||||
{
|
||||
"name": "uniform-range",
|
||||
"value": 1.0,
|
||||
"distribution": "uniform",
|
||||
"min": 5,
|
||||
"max": 5,
|
||||
},
|
||||
"Parameter 'uniform-range' requires 'min' < 'max' for uniform distribution",
|
||||
),
|
||||
(
|
||||
{
|
||||
"name": "triangular-mode",
|
||||
"value": 5.0,
|
||||
"distribution": "triangular",
|
||||
"min": 1,
|
||||
"max": 3,
|
||||
"mode": 5,
|
||||
},
|
||||
"Parameter 'triangular-mode' mode must be within min/max bounds for triangular distribution",
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_run_simulation_parameter_validation_errors(
|
||||
parameter_payload: Dict[str, Any], error_message: str
|
||||
) -> None:
|
||||
with pytest.raises(ValueError) as exc:
|
||||
run_simulation([parameter_payload])
|
||||
assert str(exc.value) == error_message
|
||||
|
||||
|
||||
def test_run_simulation_normal_std_dev_fallback():
|
||||
params: List[Dict[str, Any]] = [
|
||||
{
|
||||
"name": "std-dev-fallback",
|
||||
"value": 10.0,
|
||||
"distribution": "normal",
|
||||
"std_dev": 0,
|
||||
}
|
||||
]
|
||||
results = run_simulation(params, iterations=3, seed=99)
|
||||
assert len(results) == 3
|
||||
assert all("result" in entry for entry in results)
|
||||
|
||||
|
||||
def test_simulation_endpoint_no_params(client: TestClient):
|
||||
scenario_payload = {
|
||||
scenario_payload: Dict[str, Any] = {
|
||||
"name": f"NoParamScenario-{uuid4()}",
|
||||
"description": "No parameters run",
|
||||
}
|
||||
@@ -50,7 +117,7 @@ def test_simulation_endpoint_no_params(client: TestClient):
|
||||
def test_simulation_endpoint_success(
|
||||
client: TestClient, db_session: Session
|
||||
):
|
||||
scenario_payload = {
|
||||
scenario_payload: Dict[str, Any] = {
|
||||
"name": f"SimScenario-{uuid4()}",
|
||||
"description": "Simulation test",
|
||||
}
|
||||
@@ -58,10 +125,10 @@ def test_simulation_endpoint_success(
|
||||
assert scenario_resp.status_code == 200
|
||||
scenario_id = scenario_resp.json()["id"]
|
||||
|
||||
params = [
|
||||
params: List[Dict[str, Any]] = [
|
||||
{"name": "param1", "value": 2.5, "distribution": "normal", "std_dev": 0.5}
|
||||
]
|
||||
payload = {
|
||||
payload: Dict[str, Any] = {
|
||||
"scenario_id": scenario_id,
|
||||
"parameters": params,
|
||||
"iterations": 10,
|
||||
@@ -85,7 +152,7 @@ def test_simulation_endpoint_success(
|
||||
|
||||
|
||||
def test_simulation_endpoint_uses_stored_parameters(client: TestClient):
|
||||
scenario_payload = {
|
||||
scenario_payload: Dict[str, Any] = {
|
||||
"name": f"StoredParams-{uuid4()}",
|
||||
"description": "Stored parameter simulation",
|
||||
}
|
||||
@@ -93,7 +160,7 @@ def test_simulation_endpoint_uses_stored_parameters(client: TestClient):
|
||||
assert scenario_resp.status_code == 200
|
||||
scenario_id = scenario_resp.json()["id"]
|
||||
|
||||
parameter_payload = {
|
||||
parameter_payload: Dict[str, Any] = {
|
||||
"scenario_id": scenario_id,
|
||||
"name": "grade",
|
||||
"value": 1.5,
|
||||
|
||||
Reference in New Issue
Block a user