Browse Source

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.

pull/9928/head
dotX12 2 years ago
parent
commit
032c5077da
  1. 24
      tests/test_compat.py

24
tests/test_compat.py

@ -1,4 +1,4 @@
from typing import List, Union
from typing import FrozenSet, List, Optional, Set, Union
from fastapi import FastAPI, UploadFile
from fastapi._compat import (
@ -6,6 +6,7 @@ from fastapi._compat import (
Undefined,
_get_model_config,
is_bytes_sequence_annotation,
is_sequence_field,
is_uploadfile_sequence_annotation,
)
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
# class "feature"
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…
Cancel
Save