File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -127,6 +127,14 @@ class SelectForm(BaseModel):
127127 search_select_single : str = Field (json_schema_extra = {'search_url' : '/api/forms/search' })
128128 search_select_multiple : list [str ] = Field (json_schema_extra = {'search_url' : '/api/forms/search' })
129129
130+ @field_validator ('select_multiple' , 'search_select_multiple' , mode = 'before' )
131+ @classmethod
132+ def correct_select_multiple (cls , v : list [str ]) -> list [str ]:
133+ if isinstance (v , list ):
134+ return v
135+ else :
136+ return [v ]
137+
130138
131139@router .post ('/select' , response_model = FastUI , response_model_exclude_none = True )
132140async def select_form_post (form : Annotated [SelectForm , fastui_form (SelectForm )]):
Original file line number Diff line number Diff line change 55from fastapi .testclient import TestClient
66
77from . import app
8+ from .forms import ToolEnum
89
910
1011@pytest .fixture
@@ -74,4 +75,20 @@ def test_menu_links(client: TestClient, url: str):
7475 assert isinstance (data , list )
7576
7677
78+ def test_forms_validate_correct_select_multiple ():
79+ with client as _client :
80+ countries = _client .get ('api/forms/search' , params = {'q' : None })
81+ countries_options = countries .json ()['options' ]
82+ r = client .post (
83+ 'api/forms/select' ,
84+ data = {
85+ 'select_single' : ToolEnum ._member_names_ [0 ],
86+ 'select_multiple' : ToolEnum ._member_names_ [0 ],
87+ 'search_select_single' : countries_options [0 ]['options' ][0 ]['value' ],
88+ 'search_select_multiple' : countries_options [0 ]['options' ][0 ]['value' ],
89+ },
90+ )
91+ assert r .status_code == 200
92+
93+
7794# TODO tests for forms, including submission
You can’t perform that action at this time.
0 commit comments