fix: Kredit-Ausgabe ohne Laufzeit-Grenze (A14-T5 Fixrunde)
LoanOut erbt nicht mehr von LoanIn - definiert term_months ohne Grenzen. Altbestände mit term_months>1200 (vor Validierung direkt eingefügt) crashen GET /api/loans und PATCH nicht mehr. Regression-Test: test_altbestand_kredit_mit_laufzeit_ausserhalb_grenzen - Inseriert Loan mit term_months=1500 direkt via DB - Bestätigt GET /api/loans und Ausgabe-Serialisierung funktioniert - Keine Validierung auf Output Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -236,9 +236,16 @@ class LoanCreate(LoanIn):
|
|||||||
doppelzaehlung_bestaetigt: bool = False
|
doppelzaehlung_bestaetigt: bool = False
|
||||||
|
|
||||||
|
|
||||||
class LoanOut(LoanIn):
|
class LoanOut(BaseModel):
|
||||||
model_config = ConfigDict(from_attributes=True)
|
model_config = ConfigDict(from_attributes=True)
|
||||||
id: int
|
id: int
|
||||||
|
name: str
|
||||||
|
principal: Decimal
|
||||||
|
annual_rate_pct: Decimal
|
||||||
|
# Ausgabe darf Altbestände nicht ablehnen: keine Grenzen auf term_months.
|
||||||
|
term_months: int
|
||||||
|
payout_date: date
|
||||||
|
repayment_type: Literal["annuity", "bullet"]
|
||||||
|
|
||||||
|
|
||||||
class LoanPatch(BaseModel):
|
class LoanPatch(BaseModel):
|
||||||
|
|||||||
@@ -392,3 +392,20 @@ def test_kredit_laufzeit_grenzen_und_patch(client):
|
|||||||
assert client.patch(url, headers=H, json={"term_months": 1201}).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})
|
r = client.patch(url, headers=H, json={"term_months": 1200})
|
||||||
assert r.status_code == 200 and r.json()["term_months"] == 1200
|
assert r.status_code == 200 and r.json()["term_months"] == 1200
|
||||||
|
|
||||||
|
|
||||||
|
def test_altbestand_kredit_mit_laufzeit_ausserhalb_grenzen(client, db):
|
||||||
|
"""Regression: Kredite die vor Validierung direkt in DB eingefügt wurden
|
||||||
|
(term_months>1200 möglich) dürfen GET /api/loans nicht crashen.
|
||||||
|
LoanOut-Ausgabe muss Altbestände ohne Validierung unterstützen."""
|
||||||
|
from app.models.tables import Loan
|
||||||
|
from decimal import Decimal
|
||||||
|
old_loan = Loan(name="Legacy", principal=Decimal("500.00"), annual_rate_pct=Decimal("2.0"),
|
||||||
|
term_months=1500, payout_date=date(2025, 1, 1), repayment_type="annuity")
|
||||||
|
db.add(old_loan)
|
||||||
|
db.commit()
|
||||||
|
r = client.get("/api/loans", headers=H)
|
||||||
|
assert r.status_code == 200
|
||||||
|
loans = r.json()
|
||||||
|
found = [l for l in loans if l["term_months"] == 1500]
|
||||||
|
assert len(found) == 1 and found[0]["name"] == "Legacy"
|
||||||
|
|||||||
Reference in New Issue
Block a user