feat: Enhance currency handling and validation across scenarios

- Updated form template to prefill currency input with default value and added help text for clarity.
- Modified integration tests to assert more descriptive error messages for invalid currency codes.
- Introduced new tests for currency normalization and validation in various scenarios, including imports and exports.
- Added comprehensive tests for pricing calculations, ensuring defaults are respected and overrides function correctly.
- Implemented unit tests for pricing settings repository, ensuring CRUD operations and default settings are handled properly.
- Enhanced scenario pricing evaluation tests to validate currency handling and metadata defaults.
- Added simulation tests to ensure Monte Carlo runs are accurate and handle various distribution scenarios.
This commit is contained in:
2025-11-11 18:29:59 +01:00
parent 032e6d2681
commit 795a9f99f4
50 changed files with 5110 additions and 81 deletions

View File

@@ -278,3 +278,70 @@ class TestScenarioComparisonEndpoint:
detail = response.json()["detail"]
assert detail["code"] == "SCENARIO_PROJECT_MISMATCH"
assert project_a_id != project_b_id
class TestScenarioApiCurrencyValidation:
def test_create_api_rejects_invalid_currency(
self,
api_client: TestClient,
session_factory: sessionmaker,
) -> None:
with UnitOfWork(session_factory=session_factory) as uow:
assert uow.projects is not None
assert uow.scenarios is not None
project = Project(
name="Currency Validation Project",
operation_type=MiningOperationType.OPEN_PIT,
)
uow.projects.create(project)
project_id = project.id
response = api_client.post(
f"/projects/{project_id}/scenarios",
json={
"name": "Invalid Currency Scenario",
"currency": "US",
},
)
assert response.status_code == 422
detail = response.json().get("detail", [])
assert any(
"Invalid currency code" in item.get("msg", "") for item in detail
), detail
with UnitOfWork(session_factory=session_factory) as uow:
assert uow.scenarios is not None
scenarios = uow.scenarios.list_for_project(project_id)
assert scenarios == []
def test_create_api_normalises_currency(
self,
api_client: TestClient,
session_factory: sessionmaker,
) -> None:
with UnitOfWork(session_factory=session_factory) as uow:
assert uow.projects is not None
assert uow.scenarios is not None
project = Project(
name="Currency Normalisation Project",
operation_type=MiningOperationType.OPEN_PIT,
)
uow.projects.create(project)
project_id = project.id
response = api_client.post(
f"/projects/{project_id}/scenarios",
json={
"name": "Normalised Currency Scenario",
"currency": "cad",
},
)
assert response.status_code == 201
with UnitOfWork(session_factory=session_factory) as uow:
assert uow.scenarios is not None
scenarios = uow.scenarios.list_for_project(project_id)
assert len(scenarios) == 1
assert scenarios[0].currency == "CAD"