Python 88.3%
TypeScript 7.6%
Shell 4.1%
1"""Files API: resumable upload protocol, get/list/delete, fileData usage, 403 semantics. Verified 2026-09-18 (free)."""2from __future__ import annotations34from tests.gemini._core_helpers import call, gc567def test_resumable_upload_lifecycle(gemini, models):8 data = b"The secret word in this Atlas test file is PELICAN.\n"9 st, body, hdrs = call(gemini, "POST", "/upload/v1beta/files", {"file": {"displayName": "atlas-test.txt"}},10 extra_headers={"X-Goog-Upload-Protocol": "resumable", "X-Goog-Upload-Command": "start", "X-Goog-Upload-Header-Content-Length": str(len(data)), "X-Goog-Upload-Header-Content-Type": "text/plain"}, note="test_files start")11 assert st == 200, body12 lower = {k.lower(): v for k, v in hdrs.items()}13 assert lower.get("x-goog-upload-status") == "active" and lower.get("x-goog-upload-url") and lower.get("x-goog-upload-chunk-granularity")14 path = lower["x-goog-upload-url"].split("generativelanguage.googleapis.com", 1)[1]15 st, fb, fh = call(gemini, "POST", path, None, data=data, content_type="text/plain", extra_headers={"X-Goog-Upload-Offset": "0", "X-Goog-Upload-Command": "upload, finalize", "Content-Length": str(len(data))}, note="test_files finalize")16 assert st == 200, fb17 f = fb["file"]18 assert f["name"].startswith("files/") and f["state"] == "ACTIVE" and f["source"] == "UPLOADED" and f["mimeType"] == "text/plain"19 assert f["sizeBytes"] == str(len(data)) and f["expirationTime"] and f["sha256Hash"] and f["uri"].endswith(f["name"])20 assert {k.lower(): v for k, v in fh.items()}.get("x-goog-upload-status") == "final"21 try:22 st, g, _ = call(gemini, "GET", f"/v1beta/{f['name']}", None, note="test_files get")23 assert st == 200 and g["name"] == f["name"]24 st, lst, _ = call(gemini, "GET", "/v1beta/files?pageSize=50", None, note="test_files list")25 assert st == 200 and any(x["name"] == f["name"] for x in lst.get("files", []))26 st, r, _ = call(gemini, "POST", gc(models["gemini"]), {"contents": [{"role": "user", "parts": [{"text": "What is the secret word? One word."}, {"fileData": {"fileUri": f["uri"], "mimeType": "text/plain"}}]}], "generationConfig": {"maxOutputTokens": 8}}, note="test_files use")27 assert st == 200 and "PELICAN" in r["candidates"][0]["content"]["parts"][0]["text"].upper()28 finally:29 st, _, _ = call(gemini, "DELETE", f"/v1beta/{f['name']}", None, note="test_files delete")30 assert st == 20031 st, r, _ = call(gemini, "GET", f"/v1beta/{f['name']}", None, note="test_files get after delete")32 assert st == 403 and r["error"]["status"] == "PERMISSION_DENIED" and "may not exist" in r["error"]["message"]333435def test_unknown_file_is_403_not_404(gemini):36 st, r, _ = call(gemini, "GET", "/v1beta/files/does-not-exist-atlas", None, note="test_files unknown")37 assert st == 403 and r["error"]["status"] == "PERMISSION_DENIED"383940def test_generated_files_list(gemini):41 st, r, _ = call(gemini, "GET", "/v1beta/generatedFiles?pageSize=3", None, note="test_files generatedFiles")42 assert st == 200 and isinstance(r, dict)43