- Sort Score
- Result 10 results
- Languages All
Results 1 - 10 of 14 for files (0.05 sec)
-
tests/test_tutorial/test_request_files/test_tutorial002.py
path.write_bytes(b"<file content>") path2 = tmp_path / "test2.txt" path2.write_bytes(b"<file content2>") client = TestClient(app) with path.open("rb") as file, path2.open("rb") as file2: response = client.post( "/files/", files=( ("files", ("test.txt", file)), ("files", ("test2.txt", file2)), ), )
Registered: Sun Dec 28 07:19:09 UTC 2025 - Last Modified: Sat Dec 27 18:19:10 UTC 2025 - 8.2K bytes - Viewed (0) -
tests/test_tutorial/test_request_forms_and_files/test_tutorial001.py
pathb = tmp_path / "testb.txt" patha.write_text("<file content>") pathb.write_text("<file b content>") client = TestClient(app) with patha.open("rb") as filea, pathb.open("rb") as fileb: response = client.post( "/files/", data={"token": "foo"}, files={"file": filea, "fileb": ("testb.txt", fileb, "text/plain")}, )
Registered: Sun Dec 28 07:19:09 UTC 2025 - Last Modified: Sat Dec 27 18:19:10 UTC 2025 - 7.3K bytes - Viewed (0) -
tests/test_tutorial/test_request_files/test_tutorial001.py
with path.open("rb") as file: response = client.post("/files/", files={"file": file}) assert response.status_code == 200, response.text assert response.json() == {"file_size": default_pydantic_max_size + 1} def test_post_upload_file(tmp_path, client: TestClient): path = tmp_path / "test.txt" path.write_bytes(b"<file content>") with path.open("rb") as file:Registered: Sun Dec 28 07:19:09 UTC 2025 - Last Modified: Sat Dec 27 18:19:10 UTC 2025 - 7.1K bytes - Viewed (0) -
tests/test_request_params/test_file/test_optional.py
import pytest from fastapi import FastAPI, File, UploadFile from fastapi.testclient import TestClient from .utils import get_body_model_name app = FastAPI() # ===================================================================================== # Without aliases @app.post("/optional-bytes", operation_id="optional_bytes") async def read_optional_bytes(p: Annotated[Optional[bytes], File()] = None):
Registered: Sun Dec 28 07:19:09 UTC 2025 - Last Modified: Sat Dec 27 18:19:10 UTC 2025 - 9.7K bytes - Viewed (0) -
tests/test_request_params/test_file/test_list.py
@app.post("/list-uploadfile-alias", operation_id="list_uploadfile_alias") async def read_list_uploadfile_alias( p: Annotated[list[UploadFile], File(alias="p_alias")], ): return {"file_size": [file.size for file in p]} @pytest.mark.parametrize( "path", [ "/list-bytes-alias", "/list-uploadfile-alias", ], ) def test_list_alias_schema(path: str):
Registered: Sun Dec 28 07:19:09 UTC 2025 - Last Modified: Sat Dec 27 18:31:34 UTC 2025 - 11.2K bytes - Viewed (0) -
tests/test_request_params/test_file/test_optional_list.py
p: Annotated[Optional[list[bytes]], File(alias="p_alias")] = None, ): return {"file_size": [len(file) for file in p] if p else None} @app.post("/optional-list-uploadfile-alias") async def read_optional_list_uploadfile_alias( p: Annotated[Optional[list[UploadFile]], File(alias="p_alias")] = None, ): return {"file_size": [file.size for file in p] if p else None} @pytest.mark.parametrize(
Registered: Sun Dec 28 07:19:09 UTC 2025 - Last Modified: Sat Dec 27 18:19:10 UTC 2025 - 10.4K bytes - Viewed (0) -
tests/test_tutorial/test_request_files/test_tutorial001_02.py
path.write_bytes(b"<file content>") with path.open("rb") as file: response = client.post("/files/", files={"file": file}) assert response.status_code == 200, response.text assert response.json() == {"file_size": 14} def test_post_upload_file(tmp_path: Path, client: TestClient): path = tmp_path / "test.txt" path.write_bytes(b"<file content>") with path.open("rb") as file:
Registered: Sun Dec 28 07:19:09 UTC 2025 - Last Modified: Sat Dec 27 18:19:10 UTC 2025 - 7.4K bytes - Viewed (0) -
tests/test_request_params/test_file/test_required.py
response = client.post(path, files=[("p", b"hello")]) assert response.status_code == 200 assert response.json() == {"file_size": 5} # ===================================================================================== # Alias @app.post("/required-bytes-alias", operation_id="required_bytes_alias") async def read_required_bytes_alias(p: Annotated[bytes, File(alias="p_alias")]): return {"file_size": len(p)}
Registered: Sun Dec 28 07:19:09 UTC 2025 - Last Modified: Sat Dec 27 18:19:10 UTC 2025 - 10.8K bytes - Viewed (0) -
fastapi/datastructures.py
## Example ```python from typing import Annotated from fastapi import FastAPI, File, UploadFile app = FastAPI() @app.post("/files/") async def create_file(file: Annotated[bytes, File()]): return {"file_size": len(file)} @app.post("/uploadfile/") async def create_upload_file(file: UploadFile):Registered: Sun Dec 28 07:19:09 UTC 2025 - Last Modified: Sat Dec 27 12:54:56 UTC 2025 - 5.1K bytes - Viewed (0) -
tests/test_compat.py
"embedded_value": "bar", } def test_is_bytes_sequence_annotation_union(): # For coverage # TODO: in theory this would allow declaring types that could be lists of bytes # to be read from files and other types, but I'm not even sure it's a good idea # to support it as a first class "feature" assert is_bytes_sequence_annotation(Union[list[str], list[bytes]]) def test_is_uploadfile_sequence_annotation():
Registered: Sun Dec 28 07:19:09 UTC 2025 - Last Modified: Sat Dec 27 12:54:56 UTC 2025 - 4.2K bytes - Viewed (0)