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:
@@ -68,3 +68,35 @@ def test_scenario_import_commit_invalid_token_returns_404(
|
||||
)
|
||||
assert response.status_code == 404
|
||||
assert "Unknown scenario import token" in response.json()["detail"]
|
||||
|
||||
|
||||
def test_scenario_import_preview_rejects_invalid_currency(
|
||||
client: TestClient,
|
||||
unit_of_work_factory,
|
||||
) -> None:
|
||||
with unit_of_work_factory() as uow:
|
||||
assert uow.projects is not None
|
||||
project = Project(
|
||||
name="Import Currency Project",
|
||||
operation_type=MiningOperationType.OPEN_PIT,
|
||||
)
|
||||
uow.projects.create(project)
|
||||
|
||||
csv_content = (
|
||||
"project_name,name,currency\n"
|
||||
"Import Currency Project,Invalid Currency,US\n"
|
||||
)
|
||||
|
||||
response = client.post(
|
||||
"/imports/scenarios/preview",
|
||||
files={"file": ("scenarios.csv", csv_content, "text/csv")},
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
payload = response.json()
|
||||
assert payload["summary"]["accepted"] == 0
|
||||
assert payload["summary"]["errored"] == 1
|
||||
assert payload["parser_errors"]
|
||||
parser_error = payload["parser_errors"][0]
|
||||
assert parser_error["field"] == "currency"
|
||||
assert "Invalid currency code" in parser_error["message"]
|
||||
|
||||
Reference in New Issue
Block a user