62 lines
2.2 KiB
Python
62 lines
2.2 KiB
Python
"""Tests for WeCom delta mode."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
from unittest.mock import patch
|
|
|
|
from daily.config import (
|
|
delta_baseline_fallback,
|
|
env_bool,
|
|
force_push,
|
|
news_dedup_days,
|
|
skip_push_when_silent,
|
|
wecom_mode,
|
|
)
|
|
from daily.news.pushed_links import filter_unpushed_items, record_pushed_links
|
|
|
|
|
|
class ConfigHelpersTests(unittest.TestCase):
|
|
def test_wecom_mode_defaults_delta(self):
|
|
with patch.dict(os.environ, {}, clear=True):
|
|
self.assertEqual(wecom_mode(), "delta")
|
|
|
|
def test_wecom_mode_full(self):
|
|
with patch.dict(os.environ, {"DAILY_WECOM_MODE": "full"}, clear=True):
|
|
self.assertEqual(wecom_mode(), "full")
|
|
|
|
def test_env_bool_truthy(self):
|
|
with patch.dict(os.environ, {"DAILY_FORCE_PUSH": "1"}, clear=True):
|
|
self.assertTrue(env_bool("DAILY_FORCE_PUSH", False))
|
|
|
|
def test_skip_push_when_silent_default(self):
|
|
with patch.dict(os.environ, {}, clear=True):
|
|
self.assertTrue(skip_push_when_silent())
|
|
|
|
def test_news_dedup_days_default(self):
|
|
with patch.dict(os.environ, {}, clear=True):
|
|
self.assertEqual(news_dedup_days(), 7)
|
|
|
|
def test_delta_baseline_fallback_default(self):
|
|
with patch.dict(os.environ, {}, clear=True):
|
|
self.assertEqual(delta_baseline_fallback(), "full")
|
|
|
|
|
|
class NewsPushedLinksTests(unittest.TestCase):
|
|
def test_filter_and_record_roundtrip(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
cache = Path(tmp) / "pushed-news-links.json"
|
|
items = [
|
|
{"title": "A", "link": "https://example.com/a?utm_source=x"},
|
|
{"title": "B", "link": "https://example.com/b"},
|
|
]
|
|
with patch("daily.news.pushed_links._cache_path", return_value=cache):
|
|
with patch("daily.news.pushed_links.news_dedup_days", return_value=7):
|
|
record_pushed_links("2026-07-08", ["https://example.com/a"])
|
|
out = filter_unpushed_items(items, date_str="2026-07-09")
|
|
self.assertEqual(len(out), 1)
|
|
self.assertEqual(out[0]["link"], "https://example.com/b")
|