1
+ import enum
1
2
from contextlib import asynccontextmanager
2
3
from io import BytesIO
3
- from typing import List , Literal , Tuple , Union
4
+ from typing import List , Tuple , Union
4
5
5
6
import pytest
6
7
from fastapi import HTTPException
@@ -471,8 +472,15 @@ def test_form_textarea_form_fields():
471
472
}
472
473
473
474
475
+ class SelectEnum (str , enum .Enum ):
476
+ one = 'one'
477
+ two = 'two'
478
+
479
+
474
480
class 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' )
476
484
477
485
478
486
def test_form_select_multiple ():
@@ -481,15 +489,34 @@ def test_form_select_multiple():
481
489
assert m .model_dump (by_alias = True , exclude_none = True ) == {
482
490
'formFields' : [
483
491
{
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' ,
485
512
'locked' : False ,
486
513
'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 ' }],
489
516
'required' : True ,
490
517
'title' : ['Select Multiple' ],
491
518
'type' : 'FormFieldSelect' ,
492
- }
519
+ },
493
520
],
494
521
'method' : 'POST' ,
495
522
'submitUrl' : '/foobar/' ,
0 commit comments