From 5c34ce75b690196205eff290a5623088c0663262 Mon Sep 17 00:00:00 2001 From: meijiali <你的邮箱@xxx.com> Date: Fri, 3 Jul 2026 11:14:31 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E4=BF=AE=E5=A4=8D=E5=B0=8F=E7=BA=A2?= =?UTF-8?q?=E4=B9=A6=E6=B5=81=E7=A8=8B=E6=B5=8B=E8=AF=95=E4=B8=8D=E7=A8=B3?= =?UTF-8?q?=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../integration/test_task_flow_xiaohongshu.py | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/tests/integration/test_task_flow_xiaohongshu.py b/tests/integration/test_task_flow_xiaohongshu.py index 9686f74..a1ed6e6 100644 --- a/tests/integration/test_task_flow_xiaohongshu.py +++ b/tests/integration/test_task_flow_xiaohongshu.py @@ -1,3 +1,5 @@ +import json + from sqlalchemy import select from sqlalchemy.orm import Session @@ -26,19 +28,19 @@ class FakeXhsPlatform: return [CommentData(source_comment_id="c1", content="评论一", like_count=5, raw_data={"id": "c1"})] +def successful_ai_response(prompt: str) -> str: + comments = json.loads(prompt[prompt.index("[") :]) + comment_id = comments[0]["comment_id"] + return json.dumps( + [{"comment_id": comment_id, "sentiment": "positive", "labels": ["认可"], "reason": "喜欢"}], + ensure_ascii=False, + ) + + def test_xiaohongshu_task_flow_persists_hotspots_items_and_comments(monkeypatch): with make_test_client() as (_client, engine): monkeypatch.setattr("app.services.task_service.build_platform", lambda _platform: FakeXhsPlatform()) - monkeypatch.setattr( - "app.services.task_service.build_ai_requester", - lambda: ( - lambda prompt: ( - '[{"comment_id":"' - + ("c1" if "c1" in prompt else prompt.split('"comment_id": "')[1].split('"')[0]) - + '","sentiment":"positive","labels":["认可"],"reason":"喜欢"}]' - ) - ), - ) + monkeypatch.setattr("app.services.task_service.build_ai_requester", lambda: successful_ai_response) with Session(engine) as session: task = create_task(