test: update video generation tests for queued jobs and gallery redirects
This commit is contained in:
1 parent
a4b874598d
commit
b5dda5ed97
3 files changed
+201
-88
No files matched your search
@@ -10,6 +10,13 @@ os.environ.setdefault("BACKEND_URL", "http://backend-mock")
|
||||
|
||||
from app.main import app # noqa: E402
|
||||
|
||||
# All backend HTTP calls happen in app.helpers via `httpx.request`. The tests
|
||||
# below (many written pre-refactor) patch "frontend.app.main.httpx.request";
|
||||
# expose httpx on the entry module so that target keeps resolving to the shared
|
||||
# httpx module that helpers actually calls.
|
||||
import frontend.app.main as _app_main # noqa: E402
|
||||
_app_main.httpx = httpx # noqa: E402
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
@@ -19,6 +26,25 @@ def client():
|
||||
yield c
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _bypass_token_validation(monkeypatch):
|
||||
"""Skip the per-request backend token check on protected routes.
|
||||
|
||||
login_required/admin_required call helpers._validate_and_refresh(), which
|
||||
makes an extra "/auth/validate" HTTP request. These tests mock only the
|
||||
data endpoints they exercise, so validation is stubbed to succeed without
|
||||
making an HTTP call.
|
||||
"""
|
||||
# helpers.py can be imported under two identities ("app.helpers" used by the
|
||||
# blueprints, and "frontend.app.helpers") when running from the repo root;
|
||||
# patch both so the stubbed validation is always seen.
|
||||
import app.helpers as _app_helpers
|
||||
import frontend.app.helpers as _frontend_helpers
|
||||
monkeypatch.setattr(_app_helpers, "_validate_and_refresh", lambda: True)
|
||||
monkeypatch.setattr(_frontend_helpers,
|
||||
"_validate_and_refresh", lambda: True)
|
||||
|
||||
|
||||
def _mock_response(status_code: int, json_data) -> MagicMock:
|
||||
m = MagicMock()
|
||||
m.status_code = status_code
|
||||
@@ -341,6 +367,7 @@ def test_generate_video_page_renders(client):
|
||||
|
||||
|
||||
def test_generate_video_text_mode(client):
|
||||
"""Submitting a text-to-video job redirects to the gallery."""
|
||||
_set_auth(client)
|
||||
mock = _mock_response(
|
||||
200, {"id": "v1", "model": "openai/sora-2-pro", "status": "queued"})
|
||||
@@ -350,11 +377,12 @@ def test_generate_video_text_mode(client):
|
||||
"prompt": "A sunset", "aspect_ratio": "16:9",
|
||||
"duration_seconds": "10", "resolution": "720p",
|
||||
})
|
||||
assert resp.status_code == 200
|
||||
assert b"queued" in resp.data
|
||||
assert resp.status_code == 302
|
||||
assert "/gallery" in resp.headers["Location"]
|
||||
|
||||
|
||||
def test_generate_video_image_mode(client):
|
||||
"""Submitting an image-to-video job redirects to the gallery."""
|
||||
_set_auth(client)
|
||||
mock = _mock_response(
|
||||
200, {"id": "v2", "model": "openai/sora-2-pro", "status": "processing"})
|
||||
@@ -364,8 +392,8 @@ def test_generate_video_image_mode(client):
|
||||
"image_url": "https://example.com/img.png",
|
||||
"prompt": "Pan right", "aspect_ratio": "16:9"
|
||||
})
|
||||
assert resp.status_code == 200
|
||||
assert b"processing" in resp.data
|
||||
assert resp.status_code == 302
|
||||
assert "/gallery" in resp.headers["Location"]
|
||||
|
||||
|
||||
def test_generate_upstream_error_shows_message(client):
|
||||
@@ -527,20 +555,21 @@ def test_video_status_proxy_missing_url(client):
|
||||
assert b"polling_url" in resp.data
|
||||
|
||||
|
||||
def test_video_generate_renders_polling_ui(client):
|
||||
"""When response has polling_url, template shows polling div."""
|
||||
def test_generate_video_redirects_to_detail(client):
|
||||
"""When the queued job has a db_id, submission redirects to the job detail page."""
|
||||
_set_auth(client)
|
||||
mock = _mock_response(200, {
|
||||
"id": "v1", "model": "openai/sora-2-pro", "status": "queued",
|
||||
"polling_url": "https://openrouter.ai/api/v1/videos/v1",
|
||||
"db_id": "abc-123",
|
||||
})
|
||||
with patch("frontend.app.main.httpx.request", return_value=mock):
|
||||
resp = client.post("/generate/video", data={
|
||||
"mode": "text", "model": "openai/sora-2-pro",
|
||||
"prompt": "A sunset", "aspect_ratio": "16:9",
|
||||
})
|
||||
assert resp.status_code == 200
|
||||
assert b"video-poll-status" in resp.data
|
||||
assert resp.status_code == 302
|
||||
assert "/gallery/video/abc-123" in resp.headers["Location"]
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in new issue
Block a user