Coverage for tests / test_optional_file_list.py: 100%

19 statements  

« prev     ^ index     » next       coverage.py v7.13.3, created at 2026-02-12 18:15 +0000

1from typing import Optional 1abcd

2 

3from fastapi import FastAPI, File 1abcd

4from fastapi.testclient import TestClient 1abcd

5 

6app = FastAPI() 1abcd

7 

8 

9@app.post("/files") 1abcd

10async def upload_files(files: Optional[list[bytes]] = File(None)): 1abcd

11 if files is None: 1efghij

12 return {"files_count": 0} 1fhj

13 return {"files_count": len(files), "sizes": [len(f) for f in files]} 1egi

14 

15 

16def test_optional_bytes_list(): 1abcd

17 client = TestClient(app) 1egi

18 response = client.post( 1egi

19 "/files", 

20 files=[("files", b"content1"), ("files", b"content2")], 

21 ) 

22 assert response.status_code == 200 1egi

23 assert response.json() == {"files_count": 2, "sizes": [8, 8]} 1egi

24 

25 

26def test_optional_bytes_list_no_files(): 1abcd

27 client = TestClient(app) 1fhj

28 response = client.post("/files") 1fhj

29 assert response.status_code == 200 1fhj

30 assert response.json() == {"files_count": 0} 1fhj