From 2c52be5c596d6c1f35df1b75d6f84314b8dff5a3 Mon Sep 17 00:00:00 2001 From: Vivansh Vanethiya Date: Sun, 18 Jan 2026 01:04:54 +0530 Subject: [PATCH 1/2] Add tests for form data validation and optional fields This PR adds unit tests for form data handling in the application: 1. `test_list_field_single_value`: Ensures that a single value in a list field is correctly wrapped as a list. 2. `test_alias_field_name_not_accepted`: Ensures that fields with unrecognized aliases return a 422 validation error. 3. `test_optional_int_empty_string`: Ensures that empty strings for optional integer fields are correctly converted to None. These tests improve coverage for form input validation and ensure consistent API behavior. --- tests/test_forms_single_model.py | 37 ++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/test_forms_single_model.py b/tests/test_forms_single_model.py index 7d03d29572..f48d4d3bf3 100644 --- a/tests/test_forms_single_model.py +++ b/tests/test_forms_single_model.py @@ -139,3 +139,40 @@ def test_extra_param_list(): "param": "123", "extra_params": ["456", "789"], } + + + def test_list_field_single_value(): + response = client.post( + "/form/", + data={ + "username": "Rick", + "lastname": "Sanchez", + "tags": "single", + }, + ) + assert response.status_code == 200 + assert response.json()["tags"] == ["single"] + + + def test_alias_field_name_not_accepted(): + response = client.post( + "/form/", + data={ + "username": "Rick", + "lastname": "Sanchez", + "alias_with": "something", + }, + ) + assert response.status_code == 422 + + def test_optional_int_empty_string(): + response = client.post( + "/form/", + data={ + "username": "Rick", + "lastname": "Sanchez", + "age": "", + }, + ) + assert response.status_code == 200, response.text + assert response.json()["age"] is None From d01515c4c45f2d5fa4b9adb7791ed673e166c0b4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Sat, 17 Jan 2026 19:35:55 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=8E=A8=20Auto=20format?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_forms_single_model.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_forms_single_model.py b/tests/test_forms_single_model.py index f48d4d3bf3..41e4755068 100644 --- a/tests/test_forms_single_model.py +++ b/tests/test_forms_single_model.py @@ -139,8 +139,8 @@ def test_extra_param_list(): "param": "123", "extra_params": ["456", "789"], } - - + + def test_list_field_single_value(): response = client.post( "/form/",