feat: PATCH-Endpunkte fuer Szenario-Modifikatoren und -Einmalzahlungen
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -229,3 +229,51 @@ def test_scenario_planned_crud_und_cleanup(client, db):
|
||||
assert client.delete(f"/api/scenarios/{sc['id']}", headers=H).status_code == 204
|
||||
from app.models.tables import ScenarioPlannedItem
|
||||
assert db.query(ScenarioPlannedItem).count() == 0
|
||||
|
||||
|
||||
def test_modifier_patch(client, db):
|
||||
sc = client.post("/api/scenarios", headers=H, json={"name": "ModPatch"}).json()
|
||||
m = client.post(f"/api/scenarios/{sc['id']}/modifiers", headers=H, json={
|
||||
"target_type": "recurring", "target_id": 1, "kind": "percent",
|
||||
"value": "10.00"}).json()
|
||||
# Wert aendern
|
||||
r = client.patch(f"/api/scenarios/{sc['id']}/modifiers/{m['id']}", headers=H, json={
|
||||
"target_type": "recurring", "target_id": 1, "kind": "percent", "value": "25.00"})
|
||||
assert r.status_code == 200 and r.json()["value"] == "25.00"
|
||||
# Art auf ende wechseln (mit Datum); value wird vom Validator genullt
|
||||
r = client.patch(f"/api/scenarios/{sc['id']}/modifiers/{m['id']}", headers=H, json={
|
||||
"target_type": "recurring", "target_id": 1, "kind": "ende",
|
||||
"end_date": "2026-08-31"})
|
||||
assert r.status_code == 200
|
||||
assert r.json()["kind"] == "ende" and r.json()["end_date"] == "2026-08-31"
|
||||
# ende ohne Datum -> 422
|
||||
r = client.patch(f"/api/scenarios/{sc['id']}/modifiers/{m['id']}", headers=H, json={
|
||||
"target_type": "recurring", "target_id": 1, "kind": "ende"})
|
||||
assert r.status_code == 422
|
||||
# zurueck auf remove: end_date wird genullt
|
||||
r = client.patch(f"/api/scenarios/{sc['id']}/modifiers/{m['id']}", headers=H, json={
|
||||
"target_type": "recurring", "target_id": 1, "kind": "remove",
|
||||
"end_date": "2026-08-31"})
|
||||
assert r.status_code == 200 and r.json()["end_date"] is None
|
||||
# fremdes Szenario -> 404
|
||||
other = client.post("/api/scenarios", headers=H, json={"name": "ModPatch2"}).json()
|
||||
r = client.patch(f"/api/scenarios/{other['id']}/modifiers/{m['id']}", headers=H, json={
|
||||
"target_type": "recurring", "target_id": 1, "kind": "remove"})
|
||||
assert r.status_code == 404
|
||||
|
||||
|
||||
def test_scenario_planned_patch(client, db):
|
||||
sc = client.post("/api/scenarios", headers=H, json={"name": "SpiPatch"}).json()
|
||||
p = client.post(f"/api/scenarios/{sc['id']}/planned", headers=H, json={
|
||||
"name": "Zufluss", "amount": "5000.00", "due": "2026-07-30"}).json()
|
||||
r = client.patch(f"/api/scenarios/{sc['id']}/planned/{p['id']}", headers=H, json={
|
||||
"name": "Zufluss geaendert", "amount": "6000.00", "due": "2026-08-15"})
|
||||
assert r.status_code == 200
|
||||
body = r.json()
|
||||
assert body["name"] == "Zufluss geaendert"
|
||||
assert body["amount"] == "6000.00" and body["due"] == "2026-08-15"
|
||||
# fremdes Szenario -> 404
|
||||
other = client.post("/api/scenarios", headers=H, json={"name": "SpiPatch2"}).json()
|
||||
r = client.patch(f"/api/scenarios/{other['id']}/planned/{p['id']}", headers=H, json={
|
||||
"name": "x", "amount": "1.00", "due": "2026-08-15"})
|
||||
assert r.status_code == 404
|
||||
|
||||
Reference in New Issue
Block a user