test: 修复小红书流程测试不稳定
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
import json
|
||||||
|
|
||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
from sqlalchemy.orm import Session
|
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"})]
|
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):
|
def test_xiaohongshu_task_flow_persists_hotspots_items_and_comments(monkeypatch):
|
||||||
with make_test_client() as (_client, engine):
|
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_platform", lambda _platform: FakeXhsPlatform())
|
||||||
monkeypatch.setattr(
|
monkeypatch.setattr("app.services.task_service.build_ai_requester", lambda: successful_ai_response)
|
||||||
"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":"喜欢"}]'
|
|
||||||
)
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
task = create_task(
|
task = create_task(
|
||||||
|
|||||||
Reference in New Issue
Block a user