52 lines
1.8 KiB
Python
52 lines
1.8 KiB
Python
from app.core.config import Settings
|
|
from app.integrations.news_search_client import NewsSearchClient
|
|
|
|
|
|
def test_news_search_client_maps_grok_article_to_candidate() -> None:
|
|
# Grok Web Search结果会先转为候选信号,再进入入库和日报总结流程。
|
|
client = NewsSearchClient(Settings())
|
|
signal = client._article_to_signal(
|
|
{
|
|
"title": "国内大模型公司发布新一代Agent平台",
|
|
"summary": "中文AI新闻候选。",
|
|
"url": "https://example.cn/ai-agent-platform",
|
|
"source": "示例中文媒体",
|
|
"published_at": "2026-07-08T12:00:00Z",
|
|
"language": "zh",
|
|
"importance": 4,
|
|
"entities": ["Agent平台"],
|
|
}
|
|
)
|
|
|
|
assert signal is not None
|
|
assert signal.topic == "中文 AI 新闻"
|
|
assert signal.source_type == "news"
|
|
assert signal.source_name == "示例中文媒体"
|
|
assert signal.published_at is not None
|
|
assert signal.published_at.year == 2026
|
|
assert signal.published_at.hour == 20
|
|
assert signal.importance == 4
|
|
|
|
|
|
def test_news_search_client_parses_responses_output_text() -> None:
|
|
# Responses API会返回多段output,业务JSON只来自最终output_text。
|
|
client = NewsSearchClient(Settings())
|
|
payload = client._parse_response_json(
|
|
{
|
|
"output": [
|
|
{"type": "web_search_call", "status": "completed"},
|
|
{
|
|
"type": "message",
|
|
"content": [
|
|
{
|
|
"type": "output_text",
|
|
"text": '{"items":[{"title":"AI news","url":"https://example.com","source":"Example"}]}',
|
|
}
|
|
],
|
|
},
|
|
]
|
|
}
|
|
)
|
|
|
|
assert payload["items"][0]["title"] == "AI news"
|