Initial commit: Pixel AI comic/video creation platform
- FastAPI backend with SQLModel, Alembic migrations, AgentScope agents - Next.js 15 frontend with React 19, Tailwind, Zustand, React Flow - Multi-provider AI system (DashScope, Kling, MiniMax, Volcengine, OpenAI, etc.) - All HTTP clients migrated from sync requests to async httpx - Admin-managed API keys via environment variables - SSRF vulnerability fixed in ensure_url()
This commit is contained in:
79
backend/tests/test_video_generation_api.py
Normal file
79
backend/tests/test_video_generation_api.py
Normal file
@@ -0,0 +1,79 @@
|
||||
"""
|
||||
集成测试 - 视频生成 API (Task 5.5)
|
||||
|
||||
测试视频生成 API 端点的集成测试:
|
||||
1. 测试使用复合 ID 生成视频成功
|
||||
2. 测试无效格式返回 400
|
||||
3. 测试模型不存在返回 404
|
||||
"""
|
||||
import pytest
|
||||
import sys
|
||||
import os
|
||||
|
||||
# 添加项目根目录到路径
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
||||
|
||||
from fastapi.testclient import TestClient
|
||||
from src.main import app
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
|
||||
class TestVideoGenerationAPI:
|
||||
"""视频生成 API 集成测试"""
|
||||
|
||||
def test_generate_video_with_valid_composite_id(self):
|
||||
"""测试使用有效的复合 ID 生成视频成功"""
|
||||
response = client.post("/api/v1/generations/video", json={
|
||||
"prompt": "a cat playing with a ball in slow motion",
|
||||
"model": "dashscope/wan2.6-video",
|
||||
"aspectRatio": "16:9",
|
||||
"n": 1
|
||||
})
|
||||
|
||||
# 应该返回 200 或 202(任务已创建)
|
||||
assert response.status_code in [200, 202], f"Expected 200 or 202, got {response.status_code}: {response.text}"
|
||||
|
||||
data = response.json()
|
||||
assert "data" in data, f"Response missing 'data' field: {data}"
|
||||
assert "task_id" in data["data"], f"Response data missing 'task_id': {data}"
|
||||
|
||||
# 验证 task_id 不为空
|
||||
task_id = data["data"]["task_id"]
|
||||
assert task_id, "task_id should not be empty"
|
||||
assert isinstance(task_id, str), "task_id should be a string"
|
||||
|
||||
def test_generate_video_invalid_format_no_separator(self):
|
||||
"""测试无效的 model 格式(缺少分隔符)返回 400"""
|
||||
response = client.post("/api/v1/generations/video", json={
|
||||
"prompt": "a cat playing",
|
||||
"model": "wan2.6-video" # ❌ 缺少 provider
|
||||
})
|
||||
|
||||
# 应该返回 400 或 422(验证错误)
|
||||
assert response.status_code in [400, 422], f"Expected 400 or 422, got {response.status_code}: {response.text}"
|
||||
|
||||
data = response.json()
|
||||
# 错误消息应该提示正确的格式
|
||||
error_text = str(data).lower()
|
||||
assert "provider/model_key" in error_text or "format" in error_text, \
|
||||
f"Error message should mention correct format: {data}"
|
||||
|
||||
def test_generate_video_model_not_found(self):
|
||||
"""测试模型不存在返回 404"""
|
||||
response = client.post("/api/v1/generations/video", json={
|
||||
"prompt": "a cat playing",
|
||||
"model": "invalid/nonexistent-video-model" # 不存在的模型
|
||||
})
|
||||
|
||||
# 应该返回 404
|
||||
assert response.status_code == 404, f"Expected 404, got {response.status_code}: {response.text}"
|
||||
|
||||
data = response.json()
|
||||
# 错误消息应该提示模型未找到
|
||||
error_text = str(data).lower()
|
||||
assert "not found" in error_text, f"Error message should mention 'not found': {data}"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
pytest.main([__file__, "-v", "--tb=short"])
|
||||
Reference in New Issue
Block a user