# test_content_pipeline.py import pytest # 导入实际的 ContentPipeline 实现 from app.services.content.content_pipeline import ContentPipeline @pytest.mark.asyncio async def test_pipeline_complete_run(): """完整Pipeline执行""" pipeline = ContentPipeline() request = { "content": "这是一篇测试文章内容", "title": "测试标题", "platform": "zhihu", "optimize_for": ["validation", "sensitive", "seo"] } result = await pipeline.run(request) assert result.stages is not None assert len(result.stages) > 0 assert result.outputs is not None @pytest.mark.asyncio async def test_pipeline_with_validation_fail(): """校验失败中断""" pipeline = ContentPipeline() request = { "content": "内容", "title": "这个标题太长了超过了三十个字符的限制了哈哈哈啊", "platform": "wechat", "optimize_for": ["validation"] } result = await pipeline.run(request) # 校验失败时不应继续执行后续阶段 validation_stage = next((s for s in result.stages if s.name == "validation"), None) assert validation_stage is not None assert validation_stage.passed == False @pytest.mark.asyncio async def test_pipeline_multi_platform(): """多平台适配""" pipeline = ContentPipeline() zhihu_result = await pipeline.run({ "content": "

测试内容

外部链接", "title": "测试标题", "platform": "zhihu" }) wechat_result = await pipeline.run({ "content": "

测试内容

外部链接", "title": "测试标题", "platform": "wechat" }) # 不同平台应产生不同的优化结果 assert zhihu_result.outputs != wechat_result.outputs @pytest.mark.asyncio async def test_pipeline_stage_results(): """各阶段结果记录""" pipeline = ContentPipeline() result = await pipeline.run({ "content": "内容", "title": "标题", "platform": "zhihu" }) # 检查每个阶段的结果 for stage in result.stages: assert stage.name is not None assert hasattr(stage, 'passed') or hasattr(stage, 'result') @pytest.mark.asyncio async def test_pipeline_error_handling(): """错误处理""" pipeline = ContentPipeline() # 无效平台应返回错误 try: result = await pipeline.run({ "content": "内容", "title": "标题", "platform": "invalid_platform" }) assert result.error is not None except ValueError as e: assert "不支持的平台" in str(e)