17174e2cf5
CI/CD Pipeline / Check if frontend-only change (push) Has been skipped
CI/CD Pipeline / Frontend Lint (push) Has been skipped
CI/CD Pipeline / PR Build API Image (push) Has been skipped
CI/CD Pipeline / PR Build Web Image (push) Has been skipped
CI/CD Pipeline / PR Build Worker Image (push) Has been skipped
CI/CD Pipeline / Validate - Migration (alembic) (push) Successful in 1m52s
CI/CD Pipeline / Validate - Type Check (mypy) (push) Successful in 1m57s
CI/CD Pipeline / Build Staging Web Image (push) Successful in 3m43s
CI/CD Pipeline / Frontend Unit Tests (push) Successful in 3m45s
CI/CD Pipeline / Build Staging Worker Image (push) Successful in 5m26s
CI/CD Pipeline / Validate - Code Quality (push) Successful in 6m44s
CI/CD Pipeline / Integration Tests (push) Successful in 2m12s
CI/CD Pipeline / Unit Tests (push) Successful in 9m0s
CI/CD Pipeline / Build Production API Image (push) Has been skipped
CI/CD Pipeline / Build Production Web Image (push) Has been skipped
CI/CD Pipeline / Build Production Worker Image (push) Has been skipped
CI/CD Pipeline / CI Gate (push) Has been skipped
CI/CD Pipeline / Deploy Production (push) Has been skipped
CI/CD Pipeline / Production Browser E2E (push) Has been skipped
CI/CD Pipeline / Build Staging API Image (push) Successful in 12m38s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Successful in 32s
CI/CD Pipeline / ACR Image Cleanup (push) Successful in 39s
CI/CD Pipeline / Staging E2E Tests (push) Failing after 1m14s
CI/CD Pipeline / Staging API Integration Tests (push) Successful in 2m50s
CI/CD Pipeline / Canary Release to Production (push) Has been skipped
Co-authored-by: xiaoxia <dev@xiaoxiajianji.com> Co-committed-by: xiaoxia <dev@xiaoxiajianji.com>
95 lines
3.1 KiB
Python
95 lines
3.1 KiB
Python
"""Tests for generation cover route — schema validation and import checks."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
from pydantic import ValidationError
|
|
|
|
|
|
def test_generation_cover_router_importable():
|
|
"""新路由模块可以正确导入"""
|
|
from app.api.routes.generation_cover import router
|
|
|
|
assert router is not None
|
|
# tags 应该是 Generation
|
|
assert "Generation" in router.tags
|
|
|
|
|
|
def test_generation_cover_route_path():
|
|
"""路由路径应为 /generate-cover"""
|
|
from app.api.routes.generation_cover import router
|
|
|
|
paths = [route.path for route in router.routes]
|
|
assert "/generate-cover" in paths
|
|
|
|
|
|
def test_generation_cover_schemas_importable():
|
|
"""Schema 可以从新模块导入"""
|
|
from app.api.routes.generation_cover import GenerateCoverRequest, GenerateCoverResponse
|
|
|
|
# 验证请求 schema 默认值
|
|
req = GenerateCoverRequest()
|
|
assert req.asset_ids == []
|
|
assert req.cover_type == "ai_frame"
|
|
assert req.frame_time is None
|
|
|
|
# 验证响应 schema
|
|
resp = GenerateCoverResponse(plan_id="p1", cover={"image_url": "http://x"})
|
|
assert resp.plan_id == "p1"
|
|
assert resp.cover["image_url"] == "http://x"
|
|
|
|
|
|
def test_generation_cover_schemas_not_in_templates_editor():
|
|
"""旧的 templates_editor/schemas.py 不再包含封面 schema"""
|
|
from app.api.routes.templates_editor import schemas as te_schemas
|
|
|
|
assert not hasattr(te_schemas, "GenerateCoverRequest")
|
|
assert not hasattr(te_schemas, "GenerateCoverResponse")
|
|
|
|
|
|
def test_templates_editor_no_cover_router():
|
|
"""templates_editor 不再包含 cover_router"""
|
|
from app.api.routes.templates_editor import _sub_routers
|
|
|
|
# cover_router 应该已被移除
|
|
for sub in _sub_routers:
|
|
for route in sub.routes:
|
|
assert "generate-cover" not in getattr(route, "path", ""), "templates_editor 不应再有 generate-cover 路由"
|
|
|
|
|
|
def test_api_router_has_generation_cover():
|
|
"""api_router 应该包含 /api/v1/generation/generate-cover 路径"""
|
|
from app.api.router import api_router
|
|
|
|
all_paths = []
|
|
for route in api_router.routes:
|
|
if hasattr(route, "path"):
|
|
all_paths.append(route.path)
|
|
# 嵌套 router
|
|
if hasattr(route, "routes"):
|
|
for sub_route in route.routes:
|
|
if hasattr(sub_route, "path"):
|
|
all_paths.append(sub_route.path)
|
|
|
|
# 应该能找到 generate-cover 路径
|
|
cover_paths = [p for p in all_paths if "generate-cover" in p]
|
|
assert len(cover_paths) > 0, f"未找到 generate-cover 路由, 所有路径: {all_paths[:20]}"
|
|
|
|
|
|
def test_generation_cover_request_validation():
|
|
"""验证请求 schema 的字段约束"""
|
|
from app.api.routes.generation_cover import GenerateCoverRequest
|
|
|
|
# frame_time 不允许负数
|
|
with pytest.raises(ValidationError):
|
|
GenerateCoverRequest(frame_time=-1.0)
|
|
|
|
# 合法的 frame_time
|
|
req = GenerateCoverRequest(frame_time=5.5)
|
|
assert req.frame_time == 5.5
|
|
|
|
# 自定义 cover_type
|
|
req2 = GenerateCoverRequest(cover_type="upload", asset_ids=["a1", "a2"])
|
|
assert req2.cover_type == "upload"
|
|
assert req2.asset_ids == ["a1", "a2"]
|