- 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.
43 lines
1.1 KiB
Python
43 lines
1.1 KiB
Python
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from services.currency import CurrencyValidationError, normalise_currency, require_currency
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"raw,expected",
|
|
[
|
|
("usd", "USD"),
|
|
(" Eur ", "EUR"),
|
|
("JPY", "JPY"),
|
|
(None, None),
|
|
],
|
|
)
|
|
def test_normalise_currency_valid_inputs(raw: str | None, expected: str | None) -> None:
|
|
assert normalise_currency(raw) == expected
|
|
|
|
|
|
@pytest.mark.parametrize("raw", ["usd1", "us", "", "12", "X Y Z"])
|
|
def test_normalise_currency_invalid_inputs(raw: str) -> None:
|
|
with pytest.raises(CurrencyValidationError):
|
|
normalise_currency(raw)
|
|
|
|
|
|
def test_require_currency_with_value() -> None:
|
|
assert require_currency("gbp", default="usd") == "GBP"
|
|
|
|
|
|
def test_require_currency_with_default() -> None:
|
|
assert require_currency(None, default="cad") == "CAD"
|
|
|
|
|
|
def test_require_currency_missing_default() -> None:
|
|
with pytest.raises(CurrencyValidationError):
|
|
require_currency(None)
|
|
|
|
|
|
def test_require_currency_invalid_default() -> None:
|
|
with pytest.raises(CurrencyValidationError):
|
|
require_currency(None, default="invalid")
|