refactor: unify asset completion workflows
This commit is contained in:
@@ -593,6 +593,51 @@ class TestAssetRetry:
|
||||
assert data["pages"][1]["image_url"] == "https://example.com/retried-page.png"
|
||||
mock_image.assert_awaited_once()
|
||||
|
||||
def test_retry_audio_success(
|
||||
self,
|
||||
auth_client: TestClient,
|
||||
test_story,
|
||||
mock_tts_provider,
|
||||
):
|
||||
response = auth_client.post(
|
||||
f"/api/stories/{test_story.id}/assets/retry",
|
||||
json={"assets": ["audio"]},
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["generation_status"] == "completed"
|
||||
assert data["image_status"] == "not_requested"
|
||||
assert data["audio_status"] == "ready"
|
||||
assert data["last_error"] is None
|
||||
mock_tts_provider.assert_awaited_once()
|
||||
|
||||
cached_audio_path = Path(settings.story_audio_cache_dir) / f"story-{test_story.id}.mp3"
|
||||
assert cached_audio_path.is_file()
|
||||
|
||||
def test_retry_audio_failure_updates_status_without_blocking_response(
|
||||
self,
|
||||
auth_client: TestClient,
|
||||
test_story,
|
||||
):
|
||||
with patch(
|
||||
"app.services.provider_router.text_to_speech",
|
||||
new_callable=AsyncMock,
|
||||
) as mock_tts:
|
||||
mock_tts.side_effect = Exception("TTS provider timeout")
|
||||
|
||||
response = auth_client.post(
|
||||
f"/api/stories/{test_story.id}/assets/retry",
|
||||
json={"assets": ["audio"]},
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["generation_status"] == "degraded_completed"
|
||||
assert data["image_status"] == "not_requested"
|
||||
assert data["audio_status"] == "failed"
|
||||
assert "TTS provider timeout" in data["last_error"]
|
||||
|
||||
def test_retry_audio_on_storybook_is_rejected(
|
||||
self,
|
||||
auth_client: TestClient,
|
||||
|
||||
Reference in New Issue
Block a user