refactor: Phase 3 拆分 generate 流水线并补全测试
提取 collect/formatters/themes 等 pipeline 模块,新增 wecom 分条、RSS、delta、Agent 工作流测试。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
54
tests/test_rss_parse.py
Normal file
54
tests/test_rss_parse.py
Normal file
@@ -0,0 +1,54 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
FIXTURES = Path(__file__).parent / "fixtures"
|
||||
|
||||
|
||||
def test_parse_sample_rss_fixture():
|
||||
from daily.news.feeds import NEWS_CATEGORIES
|
||||
from daily.news.fetch import _parse_feed
|
||||
|
||||
category = NEWS_CATEGORIES[0]
|
||||
feed_name = category.feeds[0].name
|
||||
xml = (FIXTURES / "sample-rss.xml").read_text(encoding="utf-8")
|
||||
items = _parse_feed(xml, feed_name, category)
|
||||
|
||||
assert len(items) == 1
|
||||
assert items[0]["title"] == "Sample AI headline for smoke tests"
|
||||
assert items[0]["link"] == "https://example.com/ai-news/1"
|
||||
assert items[0]["source_name"] == feed_name
|
||||
assert "minimal RSS item" in items[0]["summary"]
|
||||
|
||||
|
||||
def test_fetch_ai_news_offline(monkeypatch):
|
||||
from daily.news import fetch as news_fetch
|
||||
|
||||
sample = {
|
||||
"title": "Sample AI headline for smoke tests",
|
||||
"link": "https://example.com/ai-news/1",
|
||||
"summary": "A minimal RSS item used by offline tests.",
|
||||
"published": "Wed, 02 Jul 2026 08:00:00 GMT",
|
||||
"source_name": "OpenAI",
|
||||
"category_id": "official",
|
||||
"category_name": "厂商官方",
|
||||
"category_icon": "🏢",
|
||||
}
|
||||
|
||||
monkeypatch.setattr(
|
||||
news_fetch,
|
||||
"_fetch_news",
|
||||
lambda categories: {
|
||||
"enabled": True,
|
||||
"hours": 72,
|
||||
"categories": [{"id": "official", "name": "厂商官方", "icon": "🏢", "items": [sample]}],
|
||||
"flat": [sample],
|
||||
"stats": {"feeds_total": 1, "feeds_ok": 1, "items_raw": 1, "feeds_failed": []},
|
||||
},
|
||||
)
|
||||
|
||||
payload = news_fetch.fetch_ai_news()
|
||||
assert payload["enabled"] is True
|
||||
assert payload["flat"][0]["title"].startswith("Sample AI")
|
||||
Reference in New Issue
Block a user