Coverage for tests / test_optional_file_list.py: 100%
18 statements
« prev ^ index » next coverage.py v7.13.3, created at 2026-04-06 01:24 +0000
« prev ^ index » next coverage.py v7.13.3, created at 2026-04-06 01:24 +0000
1from fastapi import FastAPI, File 1abcd
2from fastapi.testclient import TestClient 1abcd
4app = FastAPI() 1abcd
7@app.post("/files") 1abcd
8async def upload_files(files: list[bytes] | None = File(None)): 1abcd
9 if files is None: 1efghijkl
10 return {"files_count": 0} 1egik
11 return {"files_count": len(files), "sizes": [len(f) for f in files]} 1fhjl
14def test_optional_bytes_list(): 1abcd
15 client = TestClient(app) 1fhjl
16 response = client.post( 1fhjl
17 "/files",
18 files=[("files", b"content1"), ("files", b"content2")],
19 )
20 assert response.status_code == 200 1fhjl
21 assert response.json() == {"files_count": 2, "sizes": [8, 8]} 1fhjl
24def test_optional_bytes_list_no_files(): 1abcd
25 client = TestClient(app) 1egik
26 response = client.post("/files") 1egik
27 assert response.status_code == 200 1egik
28 assert response.json() == {"files_count": 0} 1egik