# tests/test_news_relax.py from __future__ import annotations import os import unittest from unittest.mock import patch class NewsRelaxTests(unittest.TestCase): def test_strip_relax_prefix(self): from daily.news.sanitize import strip_relax_window_prefix self.assertEqual( strip_relax_window_prefix("放宽窗口:苹果起诉 OpenAI"), "苹果起诉 OpenAI", ) self.assertEqual( strip_relax_window_prefix("放宽至48小时:某新闻"), "某新闻", ) self.assertEqual( strip_relax_window_prefix("正常摘要无前缀"), "正常摘要无前缀", ) def test_backfill_disabled_does_not_reinsert_pushed(self): from daily.news.fetch import _apply_pushed_dedup_with_backfill fresh_only = [ { "link": "https://example.com/fresh", "title": "fresh", "source_name": "S", "published_fmt": "07-14", "desc_short": "新", "summary_plain": "新", } ] picked = [ { "link": "https://example.com/old", "title": "old", "source_name": "S", "published": "2026-07-13T10:00:00+00:00", "summary": "旧闻", } ] with patch("daily.news.pushed_links.filter_unpushed_items", return_value=list(fresh_only)): with patch.dict(os.environ, {"DAILY_NEWS_BACKFILL": "0"}, clear=False): out = _apply_pushed_dedup_with_backfill( fresh_only + [{"link": "https://example.com/old", "title": "old"}], picked, date_str="2026-07-14", limit=5, ) links = [x.get("link") for x in out] self.assertIn("https://example.com/fresh", links) self.assertNotIn("https://example.com/old", links) if __name__ == "__main__": unittest.main()