Enhance video generation API: add polling URL, video URLs, and error handling; implement polling status endpoint with tests
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -29,18 +29,15 @@ FAKE_IMAGE = {
|
||||
|
||||
FAKE_VIDEO = {
|
||||
"id": "gen-vid-1",
|
||||
"model": "stability/stable-video",
|
||||
"polling_url": "https://openrouter.ai/api/v1/videos/gen-vid-1",
|
||||
"status": "queued",
|
||||
"video_url": None,
|
||||
"metadata": {"estimated_seconds": 30},
|
||||
}
|
||||
|
||||
FAKE_VIDEO_DONE = {
|
||||
"id": "gen-vid-2",
|
||||
"model": "runway/gen-3",
|
||||
"polling_url": "https://openrouter.ai/api/v1/videos/gen-vid-2",
|
||||
"status": "completed",
|
||||
"video_url": "https://example.com/video.mp4",
|
||||
"metadata": None,
|
||||
"unsigned_urls": ["https://example.com/video.mp4"],
|
||||
}
|
||||
|
||||
|
||||
@@ -169,8 +166,8 @@ async def test_generate_video(client):
|
||||
data = resp.json()
|
||||
assert data["id"] == "gen-vid-1"
|
||||
assert data["status"] == "queued"
|
||||
assert data["polling_url"] == "https://openrouter.ai/api/v1/videos/gen-vid-1"
|
||||
assert data["video_url"] is None
|
||||
assert data["metadata"]["estimated_seconds"] == 30
|
||||
|
||||
|
||||
async def test_generate_video_unauthenticated(client):
|
||||
@@ -209,6 +206,45 @@ async def test_generate_video_from_image(client):
|
||||
data = resp.json()
|
||||
assert data["status"] == "completed"
|
||||
assert data["video_url"] == "https://example.com/video.mp4"
|
||||
assert data["video_urls"] == ["https://example.com/video.mp4"]
|
||||
|
||||
|
||||
async def test_poll_video_status(client):
|
||||
token = await _user_token(client)
|
||||
mock_result = {
|
||||
"id": "gen-vid-1",
|
||||
"status": "completed",
|
||||
"unsigned_urls": ["https://example.com/video.mp4"],
|
||||
}
|
||||
with patch("backend.app.routers.generate.openrouter.poll_video_status", new_callable=AsyncMock, return_value=mock_result):
|
||||
resp = await client.get(
|
||||
"/generate/video/status",
|
||||
params={"polling_url": "https://openrouter.ai/api/v1/videos/gen-vid-1"},
|
||||
headers={"Authorization": f"Bearer {token}"},
|
||||
)
|
||||
assert resp.status_code == 200
|
||||
data = resp.json()
|
||||
assert data["status"] == "completed"
|
||||
assert data["video_url"] == "https://example.com/video.mp4"
|
||||
|
||||
|
||||
async def test_poll_video_status_unauthenticated(client):
|
||||
resp = await client.get(
|
||||
"/generate/video/status",
|
||||
params={"polling_url": "https://openrouter.ai/api/v1/videos/gen-vid-1"},
|
||||
)
|
||||
assert resp.status_code == 401
|
||||
|
||||
|
||||
async def test_poll_video_status_upstream_error(client):
|
||||
token = await _user_token(client)
|
||||
with patch("backend.app.routers.generate.openrouter.poll_video_status", new_callable=AsyncMock, side_effect=Exception("timeout")):
|
||||
resp = await client.get(
|
||||
"/generate/video/status",
|
||||
params={"polling_url": "https://openrouter.ai/api/v1/videos/gen-vid-1"},
|
||||
headers={"Authorization": f"Bearer {token}"},
|
||||
)
|
||||
assert resp.status_code == 502
|
||||
|
||||
|
||||
async def test_generate_video_from_image_unauthenticated(client):
|
||||
|
||||
Reference in New Issue
Block a user