- 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.
72 lines
2.0 KiB
Python
72 lines
2.0 KiB
Python
from uuid import uuid4
|
|
|
|
from fastapi.testclient import TestClient
|
|
|
|
from config.database import Base, engine
|
|
from main import app
|
|
|
|
|
|
def setup_module(module):
|
|
Base.metadata.create_all(bind=engine)
|
|
|
|
|
|
def teardown_module(module):
|
|
Base.metadata.drop_all(bind=engine)
|
|
|
|
|
|
client = TestClient(app)
|
|
|
|
|
|
def test_create_and_list_distribution():
|
|
dist_name = f"NormalDist-{uuid4()}"
|
|
payload = {
|
|
"name": dist_name,
|
|
"distribution_type": "normal",
|
|
"parameters": {"mu": 0, "sigma": 1},
|
|
}
|
|
resp = client.post("/api/distributions/", json=payload)
|
|
assert resp.status_code == 200
|
|
data = resp.json()
|
|
assert data["name"] == dist_name
|
|
|
|
resp2 = client.get("/api/distributions/")
|
|
assert resp2.status_code == 200
|
|
data2 = resp2.json()
|
|
assert any(d["name"] == dist_name for d in data2)
|
|
|
|
|
|
def test_duplicate_distribution_name_allowed():
|
|
dist_name = f"DupDist-{uuid4()}"
|
|
payload = {
|
|
"name": dist_name,
|
|
"distribution_type": "uniform",
|
|
"parameters": {"min": 0, "max": 1},
|
|
}
|
|
first = client.post("/api/distributions/", json=payload)
|
|
assert first.status_code == 200
|
|
|
|
duplicate = client.post("/api/distributions/", json=payload)
|
|
assert duplicate.status_code == 200
|
|
|
|
resp = client.get("/api/distributions/")
|
|
assert resp.status_code == 200
|
|
matching = [item for item in resp.json() if item["name"] == dist_name]
|
|
assert len(matching) >= 2
|
|
|
|
|
|
def test_list_distributions_returns_all():
|
|
names = {f"ListDist-{uuid4()}" for _ in range(2)}
|
|
for name in names:
|
|
payload = {
|
|
"name": name,
|
|
"distribution_type": "triangular",
|
|
"parameters": {"min": 0, "max": 10, "mode": 5},
|
|
}
|
|
resp = client.post("/api/distributions/", json=payload)
|
|
assert resp.status_code == 200
|
|
|
|
resp = client.get("/api/distributions/")
|
|
assert resp.status_code == 200
|
|
found_names = {item["name"] for item in resp.json()}
|
|
assert names.issubset(found_names)
|