Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
63 lines
2.8 KiB
Python
63 lines
2.8 KiB
Python
from datetime import date
|
|
from decimal import Decimal
|
|
|
|
from app.models.tables import Account, Statement, Transaction
|
|
|
|
|
|
def test_account_transaction_roundtrip(db):
|
|
acc = Account(bank="DKB", iban="DE02120300000000202051", name="Giro", type="giro")
|
|
db.add(acc)
|
|
db.flush()
|
|
st = Statement(filename="a.pdf", bank="DKB", account_id=acc.id,
|
|
period_start=date(2026, 6, 1), period_end=date(2026, 6, 30),
|
|
opening_balance=Decimal("100.00"), closing_balance=Decimal("50.00"),
|
|
status="draft")
|
|
db.add(st)
|
|
db.flush()
|
|
tx = Transaction(account_id=acc.id, statement_id=st.id,
|
|
booking_date=date(2026, 6, 3), value_date=date(2026, 6, 3),
|
|
amount=Decimal("-50.00"), purpose="Miete Juni",
|
|
counterparty="Vermieter GmbH", status="draft",
|
|
dedup_hash="abc", is_duplicate=False)
|
|
db.add(tx)
|
|
db.commit()
|
|
assert db.query(Transaction).one().amount == Decimal("-50.00")
|
|
|
|
|
|
def test_scenario_planned_item_roundtrip(db):
|
|
from app.models.tables import Scenario, ScenarioPlannedItem
|
|
sc = Scenario(name="SPI-Test", description="")
|
|
db.add(sc)
|
|
db.flush()
|
|
db.add(ScenarioPlannedItem(scenario_id=sc.id, name="Einmalzahlung",
|
|
amount=Decimal("5000.00"), due=date(2026, 7, 30)))
|
|
db.commit()
|
|
item = db.query(ScenarioPlannedItem).one()
|
|
assert item.amount == Decimal("5000.00") and item.scenario_id == sc.id
|
|
|
|
|
|
def test_a14_szenario_felder_roundtrip(db):
|
|
from app.models.tables import (Category, Scenario, ScenarioModifier,
|
|
ScenarioPlannedItem, ScenarioRecurringItem)
|
|
cat = Category(name="A14-Kat")
|
|
sc = Scenario(name="A14-Modell", description="")
|
|
db.add_all([cat, sc])
|
|
db.flush()
|
|
db.add_all([
|
|
ScenarioModifier(scenario_id=sc.id, target_type="recurring", target_id=1,
|
|
kind="set", value=Decimal("-80.00"),
|
|
start_date=date(2030, 2, 1), end_date=date(2030, 3, 31)),
|
|
ScenarioPlannedItem(scenario_id=sc.id, name="E", amount=Decimal("-5.00"),
|
|
due=date(2030, 1, 1), category_id=cat.id),
|
|
ScenarioRecurringItem(scenario_id=sc.id, name="W", amount=Decimal("-10.00"),
|
|
rhythm="monthly", due_day=14,
|
|
start_date=date(2030, 1, 16), end_date=None,
|
|
category_id=cat.id),
|
|
])
|
|
db.commit()
|
|
m = db.query(ScenarioModifier).one()
|
|
assert (m.kind, m.start_date, m.end_date) == ("set", date(2030, 2, 1), date(2030, 3, 31))
|
|
assert db.query(ScenarioPlannedItem).one().category_id == cat.id
|
|
w = db.query(ScenarioRecurringItem).one()
|
|
assert (w.scenario_id, w.rhythm, w.due_day, w.category_id) == (sc.id, "monthly", 14, cat.id)
|