feat(routes): GET /sections/{section} for edit-mode cancel (#21)
This commit is contained in:
parent
c331211afd
commit
a814ec6e01
2 changed files with 30 additions and 0 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue