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:
+4
-4
@@ -21,8 +21,8 @@ class TestAccount:
|
||||
|
||||
def test_to_dict_roundtrip(self):
|
||||
a = Account(name="Test", balance=100.0)
|
||||
d = a.to_dict()
|
||||
a2 = Account.from_dict(d)
|
||||
d = a.model_dump(mode="json")
|
||||
a2 = Account.model_validate(d)
|
||||
assert a2.name == a.name
|
||||
assert a2.balance == a.balance
|
||||
assert a2.currency == a.currency
|
||||
@@ -35,8 +35,8 @@ class TestTransaction:
|
||||
|
||||
def test_roundtrip(self):
|
||||
t = Transaction(amount=-100.0, category="rent", description="test")
|
||||
d = t.to_dict()
|
||||
t2 = Transaction.from_dict(d)
|
||||
d = t.model_dump(mode="json")
|
||||
t2 = Transaction.model_validate(d)
|
||||
assert t2.amount == t.amount
|
||||
assert t2.category == t.category
|
||||
assert t2.description == t.description
|
||||
|
||||
Reference in New Issue
Block a user