From be89bde3f8e7ff990b9567778ddd0cf1068e213b Mon Sep 17 00:00:00 2001 From: sneakers-the-rat Date: Tue, 14 Apr 2026 18:59:24 -0700 Subject: [PATCH] unchecked checkboxes are absent from html form input --- .../test_request_form_models/test_tutorial003.py | 5 +++-- .../test_request_form_models/test_tutorial004.py | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/test_tutorial/test_request_form_models/test_tutorial003.py b/tests/test_tutorial/test_request_form_models/test_tutorial003.py index b4973178a3..c6b9a380d3 100644 --- a/tests/test_tutorial/test_request_form_models/test_tutorial003.py +++ b/tests/test_tutorial/test_request_form_models/test_tutorial003.py @@ -33,11 +33,12 @@ def test_post_form_checked(client: TestClient): assert response.json() == {"checkbox": True} -def test_post_form_unchecked(client: TestClient): +@pytest.mark.parametrize("data", [{}, {"checkbox": ""}]) +def test_post_form_unchecked(client: TestClient, data: dict): """ When the checkbox is not checked, the value is (maybe correctly but undesirably) still True """ - response = client.post("/form", data={"checkbox": ""}) + response = client.post("/form", data=data) response.raise_for_status() assert response.json() == {"checkbox": True} diff --git a/tests/test_tutorial/test_request_form_models/test_tutorial004.py b/tests/test_tutorial/test_request_form_models/test_tutorial004.py index 1afdeddd34..a5d010963a 100644 --- a/tests/test_tutorial/test_request_form_models/test_tutorial004.py +++ b/tests/test_tutorial/test_request_form_models/test_tutorial004.py @@ -33,12 +33,13 @@ def test_post_form_checked(client: TestClient): assert response.json() == {"checkbox": True} -def test_post_form_unchecked(client: TestClient): +@pytest.mark.parametrize("data", [{}, {"checkbox": ""}]) +def test_post_form_unchecked(client: TestClient, data: dict): """ When the checkbox is not checked, now that we have a model validator that can differentiate defaults vs. undefined, the checkbox is correctly false. """ - response = client.post("/form", data={"checkbox": ""}) + response = client.post("/form", data=data) response.raise_for_status() assert response.json() == {"checkbox": False}