Skip to content

⭐AI-driven public opinion & trend monitor with multi-platform aggregation, RSS, and smart alerts.🎯 告别信息过载,你的 AI 舆情监控助手与热点筛选工具!聚合多平台热点 + RSS 订阅,支持关键词精准筛选。AI 智能筛选新闻 + AI 翻译 + AI 分析简报直推手机,也支持接入 MCP 架构,赋能 AI 自然语言对话分析、情感洞察与趋势预测等。支持 Docker ,数据本地/云端自持。集成微信/飞书/钉钉/Telegram/邮件/ntfy/bark/slack 等渠道智能推送。

1.9 KB
Raw Blame
from datetime import datetime
from pathlib import Path
from tempfile import TemporaryDirectory
from unittest import TestCase
from unittest.mock import patch

from mcp_server.tools.storage_sync import StorageSyncTools


class _FakeS3Client:
    def download_file(self, bucket_name, remote_key, local_path):
        Path(local_path).write_bytes(b"database")


class _FakeRemoteBackend:
    bucket_name = "test-bucket"
    s3_client = _FakeS3Client()

    def __init__(self, available_date):
        self.available_date = available_date

    def list_remote_dates(self):
        return [self.available_date]


class StorageSyncTests(TestCase):
    def test_sync_downloads_news_database_to_readable_location(self):
        with TemporaryDirectory() as project_root:
            tools = StorageSyncTools(project_root)
            tools._config = {
                "app": {"timezone": "Asia/Shanghai"},
                "storage": {
                    "local": {"data_dir": "output"},
                    "remote": {
                        "endpoint_url": "https://example.invalid",
                        "bucket_name": "test-bucket",
                        "access_key_id": "test-key",
                        "secret_access_key": "test-secret",
                    },
                },
            }
            today = "2026-09-05"
            tools._remote_backend = _FakeRemoteBackend(today)

            with patch(
                "trendradar.utils.time.get_configured_time",
                return_value=datetime(2026, 9, 5),
            ):
                result = tools.sync_from_remote(days=1)

            self.assertTrue(result["success"])
            self.assertEqual(result["data"]["synced_dates"], [today])
            self.assertEqual(tools._get_local_dates(), [today])
            self.assertTrue(
                (Path(project_root) / "output" / "news" / f"{today}.db").is_file()
            )