File tree 2 files changed +25
-0
lines changed 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -127,6 +127,14 @@ class SelectForm(BaseModel):
127
127
search_select_single : str = Field (json_schema_extra = {'search_url' : '/api/forms/search' })
128
128
search_select_multiple : list [str ] = Field (json_schema_extra = {'search_url' : '/api/forms/search' })
129
129
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
+
130
138
131
139
@router .post ('/select' , response_model = FastUI , response_model_exclude_none = True )
132
140
async def select_form_post (form : Annotated [SelectForm , fastui_form (SelectForm )]):
Original file line number Diff line number Diff line change 5
5
from fastapi .testclient import TestClient
6
6
7
7
from . import app
8
+ from .forms import ToolEnum
8
9
9
10
10
11
@pytest .fixture
@@ -74,4 +75,20 @@ def test_menu_links(client: TestClient, url: str):
74
75
assert isinstance (data , list )
75
76
76
77
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
+
77
94
# TODO tests for forms, including submission
You can’t perform that action at this time.
0 commit comments