test(11-01): add Wave 0 RED scaffolds for UIE-01/02/03
- Add 8 new test functions: printers_new_returns_200, create_printer_redirects, printers_library_no_form, patch_printer, patch_printer_not_found, client_detail_returns_200, client_detail_not_found, client_links_in_printer_list - Add FIXME comments on existing POST /printers tests noting upcoming 303 change - All new tests FAIL against current code (proper RED TDD state) - Existing 13 tests remain GREEN
This commit is contained in:
@@ -14,6 +14,7 @@ def test_create_printer_persisted(client: TestClient) -> None:
|
|||||||
"""POST /printers with required fields returns 200; GET /printers contains printer name."""
|
"""POST /printers with required fields returns 200; GET /printers contains printer name."""
|
||||||
from imptune.db.models import Printer
|
from imptune.db.models import Printer
|
||||||
|
|
||||||
|
# FIXME: POST /printers will return 303 after Task 2 — update status_code assertion then
|
||||||
resp = client.post(
|
resp = client.post(
|
||||||
"/printers",
|
"/printers",
|
||||||
data={
|
data={
|
||||||
@@ -38,6 +39,7 @@ def test_create_printer_duplex(client: TestClient) -> None:
|
|||||||
"""POST /printers with duplex_mode=LongEdge persists correctly."""
|
"""POST /printers with duplex_mode=LongEdge persists correctly."""
|
||||||
from imptune.db.models import Printer
|
from imptune.db.models import Printer
|
||||||
|
|
||||||
|
# FIXME: POST /printers will return 303 after Task 2 — update status_code assertion then
|
||||||
resp = client.post(
|
resp = client.post(
|
||||||
"/printers",
|
"/printers",
|
||||||
data={
|
data={
|
||||||
@@ -58,6 +60,7 @@ def test_create_printer_color_mode(client: TestClient) -> None:
|
|||||||
"""POST /printers with color_mode not sent (unchecked) sets color_mode=False."""
|
"""POST /printers with color_mode not sent (unchecked) sets color_mode=False."""
|
||||||
from imptune.db.models import Printer
|
from imptune.db.models import Printer
|
||||||
|
|
||||||
|
# FIXME: POST /printers will return 303 after Task 2 — update status_code assertion then
|
||||||
resp = client.post(
|
resp = client.post(
|
||||||
"/printers",
|
"/printers",
|
||||||
data={
|
data={
|
||||||
@@ -78,6 +81,7 @@ def test_create_printer_paper_size(client: TestClient) -> None:
|
|||||||
"""POST /printers with paper_size=Letter persists correctly."""
|
"""POST /printers with paper_size=Letter persists correctly."""
|
||||||
from imptune.db.models import Printer
|
from imptune.db.models import Printer
|
||||||
|
|
||||||
|
# FIXME: POST /printers will return 303 after Task 2 — update status_code assertion then
|
||||||
resp = client.post(
|
resp = client.post(
|
||||||
"/printers",
|
"/printers",
|
||||||
data={
|
data={
|
||||||
@@ -98,6 +102,7 @@ def test_create_printer_collate(client: TestClient) -> None:
|
|||||||
"""POST /printers with collate not sent (unchecked) sets collate=False."""
|
"""POST /printers with collate not sent (unchecked) sets collate=False."""
|
||||||
from imptune.db.models import Printer
|
from imptune.db.models import Printer
|
||||||
|
|
||||||
|
# FIXME: POST /printers will return 303 after Task 2 — update status_code assertion then
|
||||||
resp = client.post(
|
resp = client.post(
|
||||||
"/printers",
|
"/printers",
|
||||||
data={
|
data={
|
||||||
@@ -137,6 +142,7 @@ def test_printer_grouped_by_client(client: TestClient) -> None:
|
|||||||
contoso = contoso_list[0]
|
contoso = contoso_list[0]
|
||||||
|
|
||||||
# Create printer assigned to that client
|
# Create printer assigned to that client
|
||||||
|
# FIXME: POST /printers will return 303 after Task 2 — update status_code assertion then
|
||||||
resp = client.post(
|
resp = client.post(
|
||||||
"/printers",
|
"/printers",
|
||||||
data={
|
data={
|
||||||
@@ -236,6 +242,7 @@ def test_delete_printer(client: TestClient) -> None:
|
|||||||
from imptune.db.models import Printer
|
from imptune.db.models import Printer
|
||||||
|
|
||||||
# Create a printer
|
# Create a printer
|
||||||
|
# FIXME: POST /printers will return 303 after Task 2 — update status_code assertion then
|
||||||
resp = client.post(
|
resp = client.post(
|
||||||
"/printers",
|
"/printers",
|
||||||
data={
|
data={
|
||||||
@@ -262,3 +269,121 @@ def test_delete_printer(client: TestClient) -> None:
|
|||||||
# GET /printers should no longer show it
|
# GET /printers should no longer show it
|
||||||
page = client.get("/printers")
|
page = client.get("/printers")
|
||||||
assert "To Delete" not in page.text
|
assert "To Delete" not in page.text
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Wave 0 scaffolds — UIE-01 (PATCH), UIE-02 (separated form/list), UIE-03 (client detail)
|
||||||
|
# These tests are RED until plan 01 task 2 and plans 02-03 implement the routes.
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
def test_printers_new_returns_200(client: TestClient) -> None:
|
||||||
|
"""GET /printers/new returns 200 with the add printer form markup."""
|
||||||
|
resp = client.get("/printers/new")
|
||||||
|
assert resp.status_code == 200
|
||||||
|
html = resp.text
|
||||||
|
# Must contain form fields
|
||||||
|
assert 'name="name"' in html or "Printer Name" in html
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_printer_redirects(client: TestClient) -> None:
|
||||||
|
"""POST /printers (no HX-Request header) returns 303 redirect to /printers."""
|
||||||
|
resp = client.post(
|
||||||
|
"/printers",
|
||||||
|
data={
|
||||||
|
"name": "Redirect Printer",
|
||||||
|
"ip_address": "192.168.2.1",
|
||||||
|
"port_name": "IP_192_168_2_1",
|
||||||
|
},
|
||||||
|
follow_redirects=False,
|
||||||
|
)
|
||||||
|
assert resp.status_code == 303
|
||||||
|
assert resp.headers["location"] == "/printers"
|
||||||
|
|
||||||
|
|
||||||
|
def test_printers_library_no_form(client: TestClient) -> None:
|
||||||
|
"""GET /printers does NOT contain the inline add-printer form markup."""
|
||||||
|
resp = client.get("/printers")
|
||||||
|
assert resp.status_code == 200
|
||||||
|
html = resp.text
|
||||||
|
# The inline form must be gone
|
||||||
|
assert 'hx-post="/printers"' not in html
|
||||||
|
assert "Save Printer" not in html
|
||||||
|
|
||||||
|
|
||||||
|
def test_patch_printer(client: TestClient) -> None:
|
||||||
|
"""PATCH /printers/{id} with updated name returns 200, updated name in response, DB updated."""
|
||||||
|
from imptune.db.models import Printer
|
||||||
|
|
||||||
|
printer = Printer.create(
|
||||||
|
name="Original Name",
|
||||||
|
ip_address="10.0.2.1",
|
||||||
|
port_name="IP_10_0_2_1",
|
||||||
|
)
|
||||||
|
|
||||||
|
resp = client.patch(
|
||||||
|
f"/printers/{printer.id}",
|
||||||
|
data={"name": "Updated Name"},
|
||||||
|
)
|
||||||
|
assert resp.status_code == 200
|
||||||
|
assert "Updated Name" in resp.text
|
||||||
|
|
||||||
|
# Verify DB update
|
||||||
|
updated = Printer.get_by_id(printer.id)
|
||||||
|
assert updated.name == "Updated Name"
|
||||||
|
|
||||||
|
|
||||||
|
def test_patch_printer_not_found(client: TestClient) -> None:
|
||||||
|
"""PATCH /printers/9999 returns 404."""
|
||||||
|
resp = client.patch("/printers/9999", data={"name": "Ghost"})
|
||||||
|
assert resp.status_code == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_client_detail_returns_200(client: TestClient) -> None:
|
||||||
|
"""GET /clients/{id} returns 200 with client name and assigned printer name."""
|
||||||
|
from imptune.db.models import Client, Printer
|
||||||
|
|
||||||
|
# Create client
|
||||||
|
cl = Client.create(name="Detail Client")
|
||||||
|
# Create printer assigned to that client
|
||||||
|
Printer.create(
|
||||||
|
name="Client Printer",
|
||||||
|
ip_address="10.0.3.1",
|
||||||
|
port_name="IP_10_0_3_1",
|
||||||
|
client=cl,
|
||||||
|
)
|
||||||
|
|
||||||
|
resp = client.get(f"/clients/{cl.id}")
|
||||||
|
assert resp.status_code == 200
|
||||||
|
html = resp.text
|
||||||
|
assert "Detail Client" in html
|
||||||
|
assert "Client Printer" in html
|
||||||
|
|
||||||
|
|
||||||
|
def test_client_detail_not_found(client: TestClient) -> None:
|
||||||
|
"""GET /clients/9999 returns 404."""
|
||||||
|
resp = client.get("/clients/9999")
|
||||||
|
assert resp.status_code == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_client_links_in_printer_list(client: TestClient) -> None:
|
||||||
|
"""GET /printers with a printer assigned to a client contains href to client detail."""
|
||||||
|
from imptune.db.models import Client, Printer
|
||||||
|
|
||||||
|
# Create client via POST /clients
|
||||||
|
resp = client.post("/clients", data={"name": "Link Client"})
|
||||||
|
assert resp.status_code == 200
|
||||||
|
|
||||||
|
cl = Client.get(Client.name == "Link Client")
|
||||||
|
|
||||||
|
# Create printer assigned to that client
|
||||||
|
Printer.create(
|
||||||
|
name="Linked Printer",
|
||||||
|
ip_address="10.0.4.1",
|
||||||
|
port_name="IP_10_0_4_1",
|
||||||
|
client=cl,
|
||||||
|
)
|
||||||
|
|
||||||
|
resp = client.get("/printers")
|
||||||
|
assert resp.status_code == 200
|
||||||
|
assert f'href="/clients/{cl.id}"' in resp.text
|
||||||
|
|||||||
Reference in New Issue
Block a user