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(