Refactor Phase 2: Split stories.py into Schema/Service/Controller, add missing endpoints, fix async bug

This commit is contained in:
zhangtuo
2026-02-10 17:14:54 +08:00
parent c351d16d3e
commit 9cdff18336
13 changed files with 881 additions and 612 deletions

View File

@@ -57,7 +57,6 @@ class TestStoryGenerate:
assert data["mode"] == "generated"
@pytest.mark.skip(reason="GET /api/stories (列表) 端点尚未实现")
class TestStoryList:
"""故事列表测试。"""
@@ -94,7 +93,6 @@ class TestStoryList:
assert len(data) == 0
@pytest.mark.skip(reason="GET /api/stories/{id} (详情) 端点尚未实现")
class TestStoryDetail:
"""故事详情测试。"""
@@ -118,7 +116,6 @@ class TestStoryDetail:
assert data["story_text"] == test_story.story_text
@pytest.mark.skip(reason="DELETE /api/stories/{id} (删除) 端点尚未实现")
class TestStoryDelete:
"""故事删除测试。"""
@@ -168,7 +165,6 @@ class TestRateLimit:
assert "Too many requests" in response.json()["detail"]
@pytest.mark.skip(reason="POST /api/image/generate/{id} 端点尚未实现")
class TestImageGenerate:
"""封面图片生成测试。"""
@@ -183,7 +179,6 @@ class TestImageGenerate:
assert response.status_code == 404
@pytest.mark.skip(reason="GET /api/audio/{id} 端点尚未实现")
class TestAudio:
"""语音朗读测试。"""
@@ -233,7 +228,7 @@ class TestGenerateFull:
def test_generate_full_image_failure(self, auth_client: TestClient, mock_text_provider):
"""图片生成失败时返回部分成功。"""
with patch("app.api.stories.generate_image", new_callable=AsyncMock) as mock_img:
with patch("app.services.story_service.generate_image", new_callable=AsyncMock) as mock_img:
mock_img.side_effect = Exception("Image API error")
response = auth_client.post(
"/api/stories/generate/full",
@@ -261,7 +256,6 @@ class TestGenerateFull:
assert call_kwargs["education_theme"] == "勇气与友谊"
@pytest.mark.skip(reason="POST /api/image/generate/{id} 端点尚未实现")
class TestImageGenerateSuccess:
"""封面图片生成成功测试。"""