T2: Pydantic v2 — replace @dataclass with BaseModel
- All domain models now use pydantic.BaseModel
- Removed manual to_dict()/from_dict() — use model_dump(mode='json')/model_validate()
- Added field validators:
- Account.balance >= 0
- Transaction.amount != 0
- RecurringCashflow.amount != 0, frequency in {daily, weekly, monthly, yearly}
- Liability.interest, payment >= 0
- ExchangeRate.rate > 0
- ForecastScenario.multipliers >= 0
- pydantic v2 native UUID handling (auto str in JSON)
- Updated excel_sync.py to use model_validate()
- Updated tests/test_model.py and tests/test_currency.py
- Added pydantic>=2.0 to pyproject.toml
Tests: 63/63 pass.
This commit is contained in:
@@ -6,8 +6,8 @@ from domain import CurrencyConverter, CurrencyError, ExchangeRate
|
||||
class TestExchangeRate:
|
||||
def test_to_dict_roundtrip(self):
|
||||
rate = ExchangeRate(from_currency="USD", to_currency="RUB", rate=80.0)
|
||||
d = rate.to_dict()
|
||||
r2 = ExchangeRate.from_dict(d)
|
||||
d = rate.model_dump(mode="json")
|
||||
r2 = ExchangeRate.model_validate(d)
|
||||
assert r2.from_currency == "USD"
|
||||
assert r2.to_currency == "RUB"
|
||||
assert r2.rate == 80.0
|
||||
|
||||
Reference in New Issue
Block a user