1+ import enum
12from contextlib import asynccontextmanager
23from io import BytesIO
3- from typing import List , Literal , Tuple , Union
4+ from typing import List , Tuple , Union
45
56import pytest
67from fastapi import HTTPException
@@ -471,8 +472,15 @@ def test_form_textarea_form_fields():
471472 }
472473
473474
475+ class SelectEnum (str , enum .Enum ):
476+ one = 'one'
477+ two = 'two'
478+
479+
474480class FormSelectMultiple (BaseModel ):
475- values : List [Literal ['foo' , 'bar' ]] = Field (title = 'Select Multiple' , description = 'First Selector' )
481+ select_single : SelectEnum = Field (title = 'Select Single' , description = 'first field' )
482+ select_single_2 : SelectEnum = Field (title = 'Select Single' ) # unset description
483+ select_multiple : List [SelectEnum ] = Field (title = 'Select Multiple' , description = 'third field' )
476484
477485
478486def test_form_select_multiple ():
@@ -481,15 +489,34 @@ def test_form_select_multiple():
481489 assert m .model_dump (by_alias = True , exclude_none = True ) == {
482490 'formFields' : [
483491 {
484- 'description' : 'First Selector' ,
492+ 'description' : 'first field' ,
493+ 'locked' : False ,
494+ 'multiple' : False ,
495+ 'name' : 'select_single' ,
496+ 'options' : [{'label' : 'One' , 'value' : 'one' }, {'label' : 'Two' , 'value' : 'two' }],
497+ 'required' : True ,
498+ 'title' : ['Select Single' ],
499+ 'type' : 'FormFieldSelect' ,
500+ },
501+ {
502+ 'locked' : False ,
503+ 'multiple' : False ,
504+ 'name' : 'select_single_2' ,
505+ 'options' : [{'label' : 'One' , 'value' : 'one' }, {'label' : 'Two' , 'value' : 'two' }],
506+ 'required' : True ,
507+ 'title' : ['Select Single' ],
508+ 'type' : 'FormFieldSelect' ,
509+ },
510+ {
511+ 'description' : 'third field' ,
485512 'locked' : False ,
486513 'multiple' : True ,
487- 'name' : 'values ' ,
488- 'options' : [{'label' : 'Foo ' , 'value' : 'foo ' }, {'label' : 'Bar ' , 'value' : 'bar ' }],
514+ 'name' : 'select_multiple ' ,
515+ 'options' : [{'label' : 'One ' , 'value' : 'one ' }, {'label' : 'Two ' , 'value' : 'two ' }],
489516 'required' : True ,
490517 'title' : ['Select Multiple' ],
491518 'type' : 'FormFieldSelect' ,
492- }
519+ },
493520 ],
494521 'method' : 'POST' ,
495522 'submitUrl' : '/foobar/' ,
0 commit comments