refactor: Tilgungsplan-Helfer schedule_for, Kredit-Laufzeit 1–1200 Monate (A14-T5)
- Neuer schedule_for() in app/engine/loans.py: vereinheitlicht Tilgungsplan-Erstellung - Laufzeit-Validierung in LoanIn und LoanPatch: 1–1200 Monate - Aufrufstellen aktualisiert (routers/planning.py, services/breakdown.py, services/projection_service.py, services/planning_chart.py) - Keine direkten loan_schedule(Decimal(...)) Aufrufe außerhalb engine/loans.py mehr - Tests für schedule_for und Laufzeit-Grenzen (1, 1200, sowie 0/-5/1201 Ablehnung) Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,8 @@ from datetime import date
|
||||
from decimal import Decimal
|
||||
from itertools import count
|
||||
|
||||
import pytest
|
||||
|
||||
from app.models.tables import Account, Category, RecurringItem, Transaction
|
||||
from app.services.suggestions import _Series, _try_merge, suggest_recurring
|
||||
|
||||
@@ -368,3 +370,25 @@ def test_suggest_volatilitaetshinweis_bei_abgetrennter_neuester_buchung(db):
|
||||
assert len(out) == 1
|
||||
assert out[0]["amount"] == Decimal("-200.00") # Betrag NICHT durch die 600er-Buchung verfaelscht
|
||||
assert "schwanken" in out[0]["hinweis"].lower()
|
||||
|
||||
|
||||
# ----------------------------------------------------------- Ausbaustufe 14: Task 5
|
||||
KREDIT = {"name": "Laufzeit-Test", "principal": "1000.00", "annual_rate_pct": "2.00",
|
||||
"payout_date": "2030-01-01", "repayment_type": "annuity"}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("laufzeit", [0, -5, 1201])
|
||||
def test_kredit_laufzeit_ausserhalb_1_bis_1200(client, laufzeit):
|
||||
r = client.post("/api/loans", headers=H, json={**KREDIT, "term_months": laufzeit})
|
||||
assert r.status_code == 422
|
||||
|
||||
|
||||
def test_kredit_laufzeit_grenzen_und_patch(client):
|
||||
a = client.post("/api/loans", headers=H, json={**KREDIT, "term_months": 1})
|
||||
b = client.post("/api/loans", headers=H, json={**KREDIT, "name": "L2", "term_months": 1200})
|
||||
assert (a.status_code, b.status_code) == (201, 201)
|
||||
url = f"/api/loans/{a.json()['id']}"
|
||||
assert client.patch(url, headers=H, json={"term_months": 0}).status_code == 422
|
||||
assert client.patch(url, headers=H, json={"term_months": 1201}).status_code == 422
|
||||
r = client.patch(url, headers=H, json={"term_months": 1200})
|
||||
assert r.status_code == 200 and r.json()["term_months"] == 1200
|
||||
|
||||
Reference in New Issue
Block a user