基于项目需求文档(PRD.md, FeatureSummary.md, DevelopmentPlan.md, UIDesign.md, User_Role_Interfaces.md)编写的 TDD 测试用例。 后端测试 (Python/pytest): - 单元测试: rule_engine, brief_parser, timestamp_alignment, video_auditor, validators - 集成测试: API Brief, Video, Review 端点 - AI 模块测试: ASR, OCR, Logo 检测服务 - 全局 fixtures 和 pytest 配置 前端测试 (TypeScript/Vitest): - 工具函数测试: utils.test.ts - 组件测试: Button, VideoPlayer, ViolationList - Hooks 测试: useVideoAudit, useVideoPlayer, useAppeal - MSW mock handlers 配置 E2E 测试 (Playwright): - 认证流程测试 - 视频上传流程测试 - 视频审核流程测试 - 申诉流程测试 所有测试当前使用 pytest.skip() / it.skip() 作为占位符, 遵循 TDD 红灯阶段 - 等待实现代码后运行。 验收标准覆盖: - ASR WER ≤ 10% - OCR 准确率 ≥ 95% - Logo F1 ≥ 0.85 - 时间戳误差 ≤ 0.5s - 频次统计准确率 ≥ 95% Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
178 lines
6.4 KiB
Python
178 lines
6.4 KiB
Python
"""
|
||
Brief API 集成测试
|
||
|
||
TDD 测试用例 - 测试 Brief 相关 API 接口
|
||
|
||
接口规范参考:DevelopmentPlan.md 第 7 章
|
||
"""
|
||
|
||
import pytest
|
||
from typing import Any
|
||
|
||
# 导入待实现的模块(TDD 红灯阶段)
|
||
# from httpx import AsyncClient
|
||
# from app.main import app
|
||
|
||
|
||
class TestBriefUploadAPI:
|
||
"""Brief 上传 API 测试"""
|
||
|
||
@pytest.mark.integration
|
||
@pytest.mark.asyncio
|
||
async def test_upload_brief_pdf_success(self) -> None:
|
||
"""测试 Brief PDF 上传成功"""
|
||
# TODO: 实现 API 测试
|
||
# async with AsyncClient(app=app, base_url="http://test") as client:
|
||
# # 登录获取 token
|
||
# login_response = await client.post("/api/v1/auth/login", json={
|
||
# "email": "agency@test.com",
|
||
# "password": "password"
|
||
# })
|
||
# token = login_response.json()["access_token"]
|
||
# headers = {"Authorization": f"Bearer {token}"}
|
||
#
|
||
# # 上传 Brief
|
||
# with open("tests/fixtures/briefs/sample_brief.pdf", "rb") as f:
|
||
# response = await client.post(
|
||
# "/api/v1/briefs/upload",
|
||
# files={"file": ("brief.pdf", f, "application/pdf")},
|
||
# data={"task_id": "task_001", "platform": "douyin"},
|
||
# headers=headers
|
||
# )
|
||
#
|
||
# assert response.status_code == 202
|
||
# data = response.json()
|
||
# assert "parsing_id" in data
|
||
# assert data["status"] == "processing"
|
||
pytest.skip("待实现:Brief 上传 API")
|
||
|
||
@pytest.mark.integration
|
||
@pytest.mark.asyncio
|
||
async def test_upload_unsupported_format_returns_400(self) -> None:
|
||
"""测试不支持的格式返回 400"""
|
||
# TODO: 实现 API 测试
|
||
# async with AsyncClient(app=app, base_url="http://test") as client:
|
||
# response = await client.post(
|
||
# "/api/v1/briefs/upload",
|
||
# files={"file": ("test.exe", b"content", "application/octet-stream")},
|
||
# data={"task_id": "task_001"},
|
||
# headers=headers
|
||
# )
|
||
#
|
||
# assert response.status_code == 400
|
||
# assert "Unsupported file format" in response.json()["error"]
|
||
pytest.skip("待实现:不支持格式测试")
|
||
|
||
@pytest.mark.integration
|
||
@pytest.mark.asyncio
|
||
async def test_upload_without_auth_returns_401(self) -> None:
|
||
"""测试无认证返回 401"""
|
||
# TODO: 实现 API 测试
|
||
# async with AsyncClient(app=app, base_url="http://test") as client:
|
||
# response = await client.post(
|
||
# "/api/v1/briefs/upload",
|
||
# files={"file": ("brief.pdf", b"content", "application/pdf")},
|
||
# data={"task_id": "task_001"}
|
||
# )
|
||
#
|
||
# assert response.status_code == 401
|
||
pytest.skip("待实现:无认证测试")
|
||
|
||
|
||
class TestBriefParsingAPI:
|
||
"""Brief 解析结果 API 测试"""
|
||
|
||
@pytest.mark.integration
|
||
@pytest.mark.asyncio
|
||
async def test_get_parsing_result_success(self) -> None:
|
||
"""测试获取解析结果成功"""
|
||
# TODO: 实现 API 测试
|
||
# async with AsyncClient(app=app, base_url="http://test") as client:
|
||
# response = await client.get(
|
||
# "/api/v1/briefs/brief_001",
|
||
# headers=headers
|
||
# )
|
||
#
|
||
# assert response.status_code == 200
|
||
# data = response.json()
|
||
# assert "selling_points" in data
|
||
# assert "forbidden_words" in data
|
||
# assert "brand_tone" in data
|
||
pytest.skip("待实现:获取解析结果 API")
|
||
|
||
@pytest.mark.integration
|
||
@pytest.mark.asyncio
|
||
async def test_get_nonexistent_brief_returns_404(self) -> None:
|
||
"""测试获取不存在的 Brief 返回 404"""
|
||
# TODO: 实现 API 测试
|
||
# async with AsyncClient(app=app, base_url="http://test") as client:
|
||
# response = await client.get(
|
||
# "/api/v1/briefs/nonexistent_id",
|
||
# headers=headers
|
||
# )
|
||
#
|
||
# assert response.status_code == 404
|
||
pytest.skip("待实现:404 测试")
|
||
|
||
|
||
class TestOnlineDocumentImportAPI:
|
||
"""在线文档导入 API 测试"""
|
||
|
||
@pytest.mark.integration
|
||
@pytest.mark.asyncio
|
||
async def test_import_feishu_doc_success(self) -> None:
|
||
"""测试飞书文档导入成功"""
|
||
# TODO: 实现 API 测试
|
||
# async with AsyncClient(app=app, base_url="http://test") as client:
|
||
# response = await client.post(
|
||
# "/api/v1/briefs/import",
|
||
# json={
|
||
# "url": "https://docs.feishu.cn/docs/valid_doc_id",
|
||
# "task_id": "task_001"
|
||
# },
|
||
# headers=headers
|
||
# )
|
||
#
|
||
# assert response.status_code == 202
|
||
pytest.skip("待实现:飞书导入 API")
|
||
|
||
@pytest.mark.integration
|
||
@pytest.mark.asyncio
|
||
async def test_import_unauthorized_link_returns_403(self) -> None:
|
||
"""测试无权限链接返回 403"""
|
||
# TODO: 实现 API 测试
|
||
# async with AsyncClient(app=app, base_url="http://test") as client:
|
||
# response = await client.post(
|
||
# "/api/v1/briefs/import",
|
||
# json={
|
||
# "url": "https://docs.feishu.cn/docs/restricted_doc",
|
||
# "task_id": "task_001"
|
||
# },
|
||
# headers=headers
|
||
# )
|
||
#
|
||
# assert response.status_code == 403
|
||
# assert "access" in response.json()["error"].lower()
|
||
pytest.skip("待实现:无权限链接测试")
|
||
|
||
|
||
class TestRuleConflictAPI:
|
||
"""规则冲突检测 API 测试"""
|
||
|
||
@pytest.mark.integration
|
||
@pytest.mark.asyncio
|
||
async def test_detect_rule_conflict(self) -> None:
|
||
"""测试规则冲突检测"""
|
||
# TODO: 实现 API 测试
|
||
# async with AsyncClient(app=app, base_url="http://test") as client:
|
||
# response = await client.post(
|
||
# "/api/v1/briefs/brief_001/check_conflicts",
|
||
# json={"platform": "douyin"},
|
||
# headers=headers
|
||
# )
|
||
#
|
||
# assert response.status_code == 200
|
||
# data = response.json()
|
||
# assert "conflicts" in data
|
||
pytest.skip("待实现:规则冲突检测 API")
|