feat: Enhance dashboard metrics and summary statistics
- Added new summary fields: variance, 5th percentile, 95th percentile, VaR (95%), and expected shortfall (95%) to the dashboard. - Updated the display logic for summary metrics to handle non-finite values gracefully. - Modified the chart rendering to include additional percentile points and tail risk metrics in tooltips. test: Introduce unit tests for consumption, costs, and other modules - Created a comprehensive test suite for consumption, costs, equipment, maintenance, production, reporting, and simulation modules. - Implemented fixtures for database setup and teardown using an in-memory SQLite database for isolated testing. - Added tests for creating, listing, and validating various entities, ensuring proper error handling and response validation. refactor: Consolidate parameter tests and remove deprecated files - Merged parameter-related tests into a new test file for better organization and clarity. - Removed the old parameter test file that was no longer in use. - Improved test coverage for parameter creation, listing, and validation scenarios. fix: Ensure proper validation and error handling in API endpoints - Added validation to reject negative amounts in consumption and production records. - Implemented checks to prevent duplicate scenario creation and ensure proper error messages are returned. - Enhanced reporting endpoint tests to validate input formats and expected outputs.
This commit is contained in:
@@ -1,14 +1,9 @@
|
||||
# ensure project root is on sys.path for module imports
|
||||
from main import app
|
||||
from routes.scenarios import router
|
||||
from config.database import Base, engine
|
||||
from fastapi.testclient import TestClient
|
||||
import pytest
|
||||
import os
|
||||
import sys
|
||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
|
||||
from uuid import uuid4
|
||||
|
||||
# Create tables for testing
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from config.database import Base, engine
|
||||
from main import app
|
||||
|
||||
|
||||
def setup_module(module):
|
||||
@@ -23,14 +18,28 @@ client = TestClient(app)
|
||||
|
||||
|
||||
def test_create_and_list_scenario():
|
||||
# Create a scenario
|
||||
scenario_name = f"Scenario-{uuid4()}"
|
||||
response = client.post(
|
||||
"/api/scenarios/", json={"name": "Test", "description": "Desc"})
|
||||
"/api/scenarios/",
|
||||
json={"name": scenario_name, "description": "Integration test"},
|
||||
)
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["name"] == "Test"
|
||||
# List scenarios
|
||||
assert data["name"] == scenario_name
|
||||
|
||||
response2 = client.get("/api/scenarios/")
|
||||
assert response2.status_code == 200
|
||||
data2 = response2.json()
|
||||
assert any(s["name"] == "Test" for s in data2)
|
||||
assert any(s["name"] == scenario_name for s in data2)
|
||||
|
||||
|
||||
def test_create_duplicate_scenario_rejected():
|
||||
scenario_name = f"Duplicate-{uuid4()}"
|
||||
payload = {"name": scenario_name, "description": "Primary"}
|
||||
|
||||
first_resp = client.post("/api/scenarios/", json=payload)
|
||||
assert first_resp.status_code == 200
|
||||
|
||||
second_resp = client.post("/api/scenarios/", json=payload)
|
||||
assert second_resp.status_code == 400
|
||||
assert second_resp.json()["detail"] == "Scenario already exists"
|
||||
|
||||
Reference in New Issue
Block a user