import re from datetime import date from decimal import Decimal from pathlib import Path from types import SimpleNamespace from app.engine.loans import add_months from app.models.tables import (Category, Loan, RecurringItem, Scenario, ScenarioModifier) D = Decimal MONAT = "2030-03" def _login(client): client.post("/login", data={"username": "admin", "password": "geheim"}) def _daten(db, gehalt="3000.00"): wohnen, eink, vers = Category(name="Wohnen"), Category(name="Einkommen"), Category(name="Versicherung") db.add_all([wohnen, eink, vers]) db.flush() db.add_all([ RecurringItem(name="Gehalt", amount=D(gehalt), rhythm="monthly", due_day=1, category_id=eink.id), RecurringItem(name="Miete", amount=D("-1000.00"), rhythm="monthly", due_day=1, category_id=wohnen.id), RecurringItem(name="Police", amount=D("-1200.00"), rhythm="yearly", due_day=1, category_id=vers.id), ]) db.commit() return wohnen def _get(client, **params): return client.get("/aufteilung", params=params) def test_menuepunkt(client): _login(client) assert 'Aufteilung' in client.get("/").text def test_standardauswahl(client): _login(client) r = _get(client) assert r.status_code == 200 assert f'value="{date.today().strftime("%Y-%m")}"' in r.text assert re.search(r'', r.text) assert len(re.findall(r'type="checkbox"[^>]*checked', r.text)) == 3 def test_tabelle_kennzahlen_torte(client, db): _login(client) _daten(db) t = _get(client, monat=MONAT).text assert "03.2030" in t assert "Fixposten (jährlich)" in t assert "-100,00 €" in t # Police 1.200 / 12 assert "33,3 %" in t # Miete 1.000 von 3.000 assert "Gesamte Einkünfte: 3.000,00 €" in t tfoot = re.search(r"
(.*?)", t, re.S).group(1) assert "Frei verfügbar" in tfoot and "1.900,00 €" in tfoot and "63,3 %" in tfoot assert '