Files
ImpTune/tests/test_printer_form.py
T
2026-04-15 17:57:12 +02:00

42 lines
1.7 KiB
Python

"""Tests for printer form template wiring — inline driver upload + OOB select."""
from fastapi.testclient import TestClient
def test_printer_form_has_inline_driver_upload(client: TestClient) -> None:
"""GET /printers/new renders printer form with:
- Driver <select> with stable id="printer-form-driver-select"
- Inline upload form with caller=printer_form hidden field
- hx-post="/drivers/upload" for the driver upload sub-form
- Plain <form action="/printers" method="post"> for the printer (no HTMX on main form)
Updated in 11-01: form moved from /printers to /printers/new (UIE-02).
"""
resp = client.get("/printers/new")
assert resp.status_code == 200
html = resp.text
# Driver select has stable id for OOB swap target
assert 'id="printer-form-driver-select"' in html, (
'Printer form driver <select> must have id="printer-form-driver-select" '
"for HTMX OOB swap to work"
)
# Inline upload form posts caller=printer_form sentinel
assert 'name="caller"' in html, 'Inline upload form missing name="caller" field'
assert 'value="printer_form"' in html, (
'Inline upload form missing value="printer_form" sentinel'
)
# Inline upload form targets /drivers/upload
assert 'hx-post="/drivers/upload"' in html, (
'Inline upload form missing hx-post="/drivers/upload"'
)
# Main printer form uses plain POST (no HTMX) so browser follows 303 redirect
assert 'action="/printers"' in html, (
'Printer form must use action="/printers" (plain HTML form, not hx-post)'
)
assert 'method="post"' in html, (
'Printer form must use method="post"'
)