Edit name/amount on budget template entries (#21) #22
2 changed files with 41 additions and 1 deletions
|
|
@ -10,7 +10,7 @@ from sqlalchemy.orm import Session
|
|||
|
||||
from quartermaster import month_service, service
|
||||
from quartermaster.db import get_session
|
||||
from quartermaster.models import SECTION_LABELS, Section
|
||||
from quartermaster.models import SECTION_LABELS, Entry, Section
|
||||
|
||||
TEMPLATES_DIR = Path(__file__).parent / "templates"
|
||||
templates = Jinja2Templates(directory=str(TEMPLATES_DIR))
|
||||
|
|
@ -150,6 +150,18 @@ def remove_entry(
|
|||
return _append_oob(response, *extras)
|
||||
|
||||
|
||||
@router.get("/entries/{entry_id}/edit", response_class=HTMLResponse)
|
||||
def edit_entry(
|
||||
entry_id: int,
|
||||
request: Request,
|
||||
db: Session = Depends(get_session),
|
||||
) -> HTMLResponse:
|
||||
entry = db.get(Entry, entry_id)
|
||||
if entry is None:
|
||||
raise HTTPException(status_code=404, detail="entry not found")
|
||||
return _render_section(request, db, entry.section, editing_id=entry.id)
|
||||
|
||||
|
||||
@router.post("/entries/{entry_id}/notes", response_class=HTMLResponse)
|
||||
def update_entry_notes(
|
||||
entry_id: int,
|
||||
|
|
|
|||
|
|
@ -86,3 +86,31 @@ def test_reject_non_debt_minimum_target(client):
|
|||
)
|
||||
response = client.post("/debt-target", data={"debt_minimum_id": "1"})
|
||||
assert response.status_code == 400
|
||||
|
||||
|
||||
def test_get_entry_edit_returns_edit_form(client):
|
||||
client.post(
|
||||
"/sections/subscription/entries",
|
||||
data={"name": "Twitch", "amount": "10.99"},
|
||||
)
|
||||
response = client.get("/entries/1/edit")
|
||||
assert response.status_code == 200
|
||||
assert 'class="entry-row editing"' in response.text
|
||||
assert 'name="name"' in response.text
|
||||
assert 'name="amount"' in response.text
|
||||
assert 'name="notes"' in response.text
|
||||
assert 'value="Twitch"' in response.text
|
||||
|
||||
|
||||
def test_get_entry_edit_missing_returns_404(client):
|
||||
response = client.get("/entries/9999/edit")
|
||||
assert response.status_code == 404
|
||||
|
||||
|
||||
def test_get_entry_edit_other_rows_stay_in_read_mode(client):
|
||||
client.post("/sections/subscription/entries", data={"name": "Twitch", "amount": "10.99"})
|
||||
client.post("/sections/subscription/entries", data={"name": "Netflix", "amount": "15.49"})
|
||||
response = client.get("/entries/1/edit")
|
||||
assert response.status_code == 200
|
||||
assert response.text.count('entry-row editing') == 1
|
||||
assert response.text.count('entry-row reading') == 1
|
||||
|
|
|
|||
Loading…
Reference in a new issue