mirror of https://github.com/tiangolo/fastapi.git
✅ A test `test_model_optional_union_v2` has been added to coverage the is_sequence_field function, which is involved in parsing data from FormData.
This commit is contained in:
parent
3d90df0718
commit
032c5077da
|
|
@ -1,4 +1,4 @@
|
||||||
from typing import List, Union
|
from typing import FrozenSet, List, Optional, Set, Union
|
||||||
|
|
||||||
from fastapi import FastAPI, UploadFile
|
from fastapi import FastAPI, UploadFile
|
||||||
from fastapi._compat import (
|
from fastapi._compat import (
|
||||||
|
|
@ -6,6 +6,7 @@ from fastapi._compat import (
|
||||||
Undefined,
|
Undefined,
|
||||||
_get_model_config,
|
_get_model_config,
|
||||||
is_bytes_sequence_annotation,
|
is_bytes_sequence_annotation,
|
||||||
|
is_sequence_field,
|
||||||
is_uploadfile_sequence_annotation,
|
is_uploadfile_sequence_annotation,
|
||||||
)
|
)
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
|
|
@ -91,3 +92,24 @@ def test_is_uploadfile_sequence_annotation():
|
||||||
# and other types, but I'm not even sure it's a good idea to support it as a first
|
# and other types, but I'm not even sure it's a good idea to support it as a first
|
||||||
# class "feature"
|
# class "feature"
|
||||||
assert is_uploadfile_sequence_annotation(Union[List[str], List[UploadFile]])
|
assert is_uploadfile_sequence_annotation(Union[List[str], List[UploadFile]])
|
||||||
|
|
||||||
|
|
||||||
|
@needs_pydanticv2
|
||||||
|
def test_model_optional_union_v2():
|
||||||
|
# For coverage
|
||||||
|
types = [
|
||||||
|
Optional[List[str]],
|
||||||
|
Union[List[int], List[float]],
|
||||||
|
Optional[Set[int]],
|
||||||
|
Union[Set[int], Set[float]],
|
||||||
|
Optional[FrozenSet[int]],
|
||||||
|
Union[List[int], None],
|
||||||
|
]
|
||||||
|
for annotation in types:
|
||||||
|
field_info = FieldInfo(annotation=annotation)
|
||||||
|
field = ModelField(name="foo", field_info=field_info)
|
||||||
|
assert is_sequence_field(field) is True
|
||||||
|
|
||||||
|
field_info_str = FieldInfo(annotation=str)
|
||||||
|
field_str = ModelField(name="foo", field_info=field_info_str)
|
||||||
|
assert is_sequence_field(field_str) is False
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue