SPB Git forge

spb/doc-api

Public
2commits 1branches 0releases
15.7 MBsize
maindefault branch
13 days agolast push
Python 88.3% TypeScript 7.6% Shell 4.1%
2.8 KB · 47 lines python
Raw Blame History
1"""cachedContents: validation errors (always), full CRUD only when the account can create caches.23On the free tier creation returns 429 TotalCachedContentStorageTokensPerModelFreeTier limit=0 (ACCOUNT_RESTRICTED) and the4CRUD test is skipped. Verified 2026-09-18.5"""6from __future__ import annotations78import pytest910from tests.gemini._core_helpers import call, gc, user1112FLASH = "gemini-3.5-flash"13FILLER = " ".join(f"Section {i}: The Atlas reference corpus documents the public API surface of large language model providers, including endpoints, parameters, streaming events, objects, errors and pricing." for i in range(1, 121))141516def test_create_validation_errors(gemini, models):17    st, r, _ = call(gemini, "POST", "/v1beta/cachedContents", {"model": f"models/{models['gemini']}", "contents": user("Too small."), "ttl": "60s"}, note="test_caching below min")18    assert st == 400 and "Cached content is too small" in r["error"]["message"] and "min_total_token_count=" in r["error"]["message"]19    st, r, _ = call(gemini, "POST", "/v1beta/cachedContents", {"contents": user("x")}, note="test_caching no model")20    assert st == 400 and "models/{model_name}" in r["error"]["message"]212223def test_v1_has_no_cached_contents(gemini):24    st, body, _ = call(gemini, "GET", "/v1/cachedContents?pageSize=1", None, note="test_caching v1 route")25    assert st == 404262728def test_cache_crud_or_restricted(gemini):29    st, cache, _ = call(gemini, "POST", "/v1beta/cachedContents", {"model": f"models/{FLASH}", "displayName": "atlas-test", "ttl": "120s", "contents": [{"role": "user", "parts": [{"text": FILLER}]}]}, note="test_caching create")30    if st == 429 and "FreeTier" in cache.get("error", {}).get("message", ""):31        pytest.skip("ACCOUNT_RESTRICTED: explicit caching quota is 0 on the free tier")32    assert st == 200, cache33    name = cache["name"]34    try:35        assert name.startswith("cachedContents/") and cache["expireTime"] and cache["usageMetadata"]["totalTokenCount"] >= 102436        st, r, _ = call(gemini, "POST", gc(FLASH), {"contents": user("Reply with OK."), "cachedContent": name, "generationConfig": {"maxOutputTokens": 8}}, note="test_caching use")37        assert st == 200 and r["usageMetadata"]["cachedContentTokenCount"] >= 102438        st, r, _ = call(gemini, "GET", f"/v1beta/{name}", None, note="test_caching get")39        assert st == 200 and r["name"] == name40        st, r, _ = call(gemini, "PATCH", f"/v1beta/{name}", {"ttl": "300s"}, note="test_caching patch")41        assert st == 200 and r["expireTime"]42        st, r, _ = call(gemini, "GET", "/v1beta/cachedContents?pageSize=5", None, note="test_caching list")43        assert st == 200 and any(c["name"] == name for c in r.get("cachedContents", []))44    finally:45        st, _, _ = call(gemini, "DELETE", f"/v1beta/{name}", None, note="test_caching delete")46        assert st == 20047