testing new features
This commit is contained in:
@@ -3,6 +3,7 @@ from pathlib import Path
|
||||
from cashflow_model import (
|
||||
Account,
|
||||
Asset,
|
||||
ExchangeRate,
|
||||
FinancialModel,
|
||||
ForecastScenario,
|
||||
Liability,
|
||||
@@ -42,6 +43,32 @@ class TestTransaction:
|
||||
|
||||
|
||||
class TestFinancialModel:
|
||||
def test_default_base_currency(self):
|
||||
model = FinancialModel()
|
||||
assert model.base_currency == "RUB"
|
||||
|
||||
def test_base_currency_roundtrip(self, tmp_path: Path):
|
||||
model = FinancialModel(base_currency="EUR")
|
||||
p = tmp_path / "model.json"
|
||||
model.save(p)
|
||||
loaded = FinancialModel.load(p)
|
||||
assert loaded.base_currency == "EUR"
|
||||
|
||||
def test_base_currency_backward_compat(self, tmp_path: Path):
|
||||
import json
|
||||
p = tmp_path / "legacy.json"
|
||||
with open(p, "w") as f:
|
||||
json.dump({"accounts": []}, f)
|
||||
loaded = FinancialModel.load(p)
|
||||
assert loaded.base_currency == "RUB"
|
||||
|
||||
def test_exchange_rates_default(self):
|
||||
model = FinancialModel()
|
||||
assert len(model.exchange_rates) == 1
|
||||
assert model.exchange_rates[0].from_currency == "USD"
|
||||
assert model.exchange_rates[0].to_currency == "RUB"
|
||||
assert model.exchange_rates[0].rate == 80.0
|
||||
|
||||
def test_save_load(self, tmp_path: Path):
|
||||
model = FinancialModel()
|
||||
model.accounts.append(Account(name="Test", balance=100.0))
|
||||
@@ -61,6 +88,8 @@ class TestFinancialModel:
|
||||
d = model.to_dict()
|
||||
assert d["accounts"] == []
|
||||
assert d["transactions"] == []
|
||||
assert d["base_currency"] == "RUB"
|
||||
assert "exchange_rates" in d
|
||||
|
||||
def test_all_entities_roundtrip(self, tmp_path: Path):
|
||||
model = FinancialModel(
|
||||
@@ -70,6 +99,7 @@ class TestFinancialModel:
|
||||
assets=[Asset(name="Stock", value=1000.0)],
|
||||
liabilities=[Liability(name="Loan", balance=500.0, interest=5.0, payment=100.0)],
|
||||
scenarios=[ForecastScenario(name="test")],
|
||||
exchange_rates=[ExchangeRate(from_currency="USD", to_currency="RUB", rate=80.0)],
|
||||
)
|
||||
p = tmp_path / "full.json"
|
||||
model.save(p)
|
||||
@@ -80,3 +110,4 @@ class TestFinancialModel:
|
||||
assert len(loaded.assets) == 1
|
||||
assert len(loaded.liabilities) == 1
|
||||
assert len(loaded.scenarios) == 1
|
||||
assert len(loaded.exchange_rates) == 1
|
||||
|
||||
Reference in New Issue
Block a user