diff --git a/src/quartermaster/routes.py b/src/quartermaster/routes.py index 8642e5c..6043e9e 100644 --- a/src/quartermaster/routes.py +++ b/src/quartermaster/routes.py @@ -190,6 +190,15 @@ def save_entry( return _append_oob(response, *extras) +@router.get("/sections/{section}", response_class=HTMLResponse) +def get_section( + section: Section, + request: Request, + db: Session = Depends(get_session), +) -> HTMLResponse: + return _render_section(request, db, section) + + @router.post("/entries/{entry_id}/notes", response_class=HTMLResponse) def update_entry_notes( entry_id: int, diff --git a/tests/test_routes.py b/tests/test_routes.py index ff301d2..2fcd9db 100644 --- a/tests/test_routes.py +++ b/tests/test_routes.py @@ -204,3 +204,24 @@ def test_post_entry_missing_returns_404(client): data={"name": "Whatever", "amount": "1.00", "notes": ""}, ) assert response.status_code == 404 + + +def test_get_section_returns_read_mode(client): + client.post( + "/sections/subscription/entries", + data={"name": "Twitch", "amount": "10.99"}, + ) + # enter edit mode first + edit = client.get("/entries/1/edit") + assert 'entry-row editing' in edit.text + # now "cancel" via GET /sections/{section} + response = client.get("/sections/subscription") + assert response.status_code == 200 + assert 'entry-row reading' in response.text + assert 'entry-row editing' not in response.text + + +def test_get_section_invalid_returns_422(client): + # FastAPI rejects an unknown Section enum value at routing + response = client.get("/sections/not_a_real_section") + assert response.status_code == 422