From 5e2d5887d1f6bc7919948e3f269cfa00e243cb9f Mon Sep 17 00:00:00 2001 From: TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> Date: Thu, 2 Apr 2026 14:05:25 +0900 Subject: feat: implement Truth Social and Federal Reserve collectors --- services/news-collector/tests/test_fed.py | 25 ++++++++++++++++++ services/news-collector/tests/test_truth_social.py | 30 ++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 services/news-collector/tests/test_fed.py create mode 100644 services/news-collector/tests/test_truth_social.py (limited to 'services/news-collector/tests') diff --git a/services/news-collector/tests/test_fed.py b/services/news-collector/tests/test_fed.py new file mode 100644 index 0000000..8acea5f --- /dev/null +++ b/services/news-collector/tests/test_fed.py @@ -0,0 +1,25 @@ +"""Tests for Federal Reserve collector.""" +import pytest +from unittest.mock import AsyncMock, patch +from news_collector.collectors.fed import FedCollector + +@pytest.fixture +def collector(): + return FedCollector() + +def test_collector_name(collector): + assert collector.name == "fed" + assert collector.poll_interval == 3600 + +async def test_is_available(collector): + assert await collector.is_available() is True + +async def test_collect_parses_rss(collector): + mock_entries = [ + {"title": "Federal Reserve issues FOMC statement", "link": "https://www.federalreserve.gov/newsevents/pressreleases/monetary20260402a.htm", "published_parsed": (2026, 4, 2, 14, 0, 0, 0, 0, 0), "summary": "The Federal Open Market Committee decided to maintain the target range..."}, + ] + with patch.object(collector, "_fetch_fed_rss", new_callable=AsyncMock, return_value=mock_entries): + items = await collector.collect() + assert len(items) == 1 + assert items[0].source == "fed" + assert items[0].category.value == "fed" diff --git a/services/news-collector/tests/test_truth_social.py b/services/news-collector/tests/test_truth_social.py new file mode 100644 index 0000000..bcf8a8c --- /dev/null +++ b/services/news-collector/tests/test_truth_social.py @@ -0,0 +1,30 @@ +"""Tests for Truth Social collector.""" +import pytest +from unittest.mock import AsyncMock, patch +from news_collector.collectors.truth_social import TruthSocialCollector + +@pytest.fixture +def collector(): + return TruthSocialCollector() + +def test_collector_name(collector): + assert collector.name == "truth_social" + assert collector.poll_interval == 900 + +async def test_is_available(collector): + assert await collector.is_available() is True + +async def test_collect_parses_posts(collector): + mock_posts = [ + {"content": "

We are imposing 25% tariffs on all steel imports!

", "created_at": "2026-04-02T12:00:00.000Z", "url": "https://truthsocial.com/@realDonaldTrump/12345", "id": "12345"}, + ] + with patch.object(collector, "_fetch_posts", new_callable=AsyncMock, return_value=mock_posts): + items = await collector.collect() + assert len(items) == 1 + assert items[0].source == "truth_social" + assert items[0].category.value == "policy" + +async def test_collect_handles_empty(collector): + with patch.object(collector, "_fetch_posts", new_callable=AsyncMock, return_value=[]): + items = await collector.collect() + assert items == [] -- cgit v1.2.3