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%
3.0 KB · 59 lines python
Raw Blame History
1"""Veo / operations / generatedFiles. Free probes (validation errors, lists) always run; a real generation2(≥ $0.20 for 4 s on veo-3.1-lite) is gated by RUN_VIDEO_TESTS=true (marker run_video_tests)."""3from __future__ import annotations45import time6import pytest78VEO = "veo-3.1-lite-generate-preview"91011def test_veo_models_only_support_predict_long_running(gemini):12    st, body, _ = gemini("GET", "/v1beta/models?pageSize=200", note="test_video models list")13    assert st == 20014    veo = [m for m in body["models"] if m["name"].split("/")[-1].startswith("veo-")]15    assert veo, "no Veo model in the live list"16    for m in veo:17        assert m["supportedGenerationMethods"] == ["predictLongRunning"]181920def test_predict_long_running_validation_errors(gemini):21    st, body, _ = gemini("POST", f"/v1beta/models/{VEO}:predictLongRunning", {}, note="test_video empty body")22    assert st == 400 and body["error"]["status"] == "INVALID_ARGUMENT" and "instances" in body["error"]["message"]23    st, body, _ = gemini("POST", f"/v1beta/models/{VEO}:predictLongRunning", {"instances": [{}]}, note="test_video empty instance")24    assert st == 400 and body["error"]["status"] == "INVALID_ARGUMENT"252627def test_generated_files_list(gemini):28    st, body, _ = gemini("GET", "/v1beta/generatedFiles?pageSize=10", note="test_video generatedFiles list")29    assert st == 200 and isinstance(body, dict)30    for f in body.get("generatedFiles", []):31        assert f["name"].startswith("generatedFiles/") and f["state"] in {"GENERATING", "GENERATED", "FAILED", "STATE_UNSPECIFIED"}323334def test_model_operations_list_and_bogus_get(gemini):35    st, body, _ = gemini("GET", f"/v1beta/models/{VEO}/operations", note="test_video operations list")36    assert st == 200 and isinstance(body, dict)37    st, body, _ = gemini("GET", f"/v1beta/models/{VEO}/operations/bogus-op", note="test_video bogus op")38    assert st in (403, 404) and body["error"]["status"] in {"PERMISSION_DENIED", "NOT_FOUND"}394041@pytest.mark.run_video_tests42def test_generate_short_video(gemini):43    body = {"instances": [{"prompt": "A plain white square slowly fading to black."}],44            "parameters": {"aspectRatio": "16:9", "resolution": "720p", "durationSeconds": "4", "personGeneration": "allow_all"}}45    st, op, _ = gemini("POST", f"/v1beta/models/{VEO}:predictLongRunning", body, est_cost_usd=0.20, note="test_video generate 4s")46    if st == 429:47        pytest.xfail("no Veo quota on this key: " + op["error"]["message"][:120])48    assert st == 200 and op["name"].startswith(f"models/{VEO}/operations/")49    t0 = time.time()50    while not op.get("done") and time.time() - t0 < 420:51        time.sleep(10)52        st, op, _ = gemini("GET", f"/v1beta/{op['name']}", note="test_video poll")53        assert st == 20054    assert op.get("done"), "operation not done after 7 min"55    assert "response" in op or "error" in op56    if "response" in op:57        uri = op["response"]["generateVideoResponse"]["generatedSamples"][0]["video"]["uri"]58        assert "files/" in uri and ":download" in uri59