summaryrefslogtreecommitdiff
path: root/services/news-collector/tests
diff options
context:
space:
mode:
authorTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2026-04-02 14:17:43 +0900
committerTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2026-04-02 14:17:43 +0900
commit35aa61c651217663406c9cd6df404f85338b2d68 (patch)
tree9d85dd87e725984d45d7b6bdfef8b316ddfc4ae7 /services/news-collector/tests
parent17540c99d5e28576a6642e23d7bd6b297513e2d8 (diff)
style: fix lint and formatting issues across news collector and shared
Diffstat (limited to 'services/news-collector/tests')
-rw-r--r--services/news-collector/tests/test_fed.py16
-rw-r--r--services/news-collector/tests/test_finnhub.py1
-rw-r--r--services/news-collector/tests/test_main.py8
-rw-r--r--services/news-collector/tests/test_reddit.py38
-rw-r--r--services/news-collector/tests/test_rss.py1
-rw-r--r--services/news-collector/tests/test_sec_edgar.py4
-rw-r--r--services/news-collector/tests/test_truth_social.py13
7 files changed, 68 insertions, 13 deletions
diff --git a/services/news-collector/tests/test_fed.py b/services/news-collector/tests/test_fed.py
index 8acea5f..d1a736b 100644
--- a/services/news-collector/tests/test_fed.py
+++ b/services/news-collector/tests/test_fed.py
@@ -1,24 +1,36 @@
"""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..."},
+ {
+ "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):
+ 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"
diff --git a/services/news-collector/tests/test_finnhub.py b/services/news-collector/tests/test_finnhub.py
index 74bd5e6..a4cf169 100644
--- a/services/news-collector/tests/test_finnhub.py
+++ b/services/news-collector/tests/test_finnhub.py
@@ -2,7 +2,6 @@
import pytest
from unittest.mock import AsyncMock, patch
-from datetime import datetime, timezone
from news_collector.collectors.finnhub import FinnhubCollector
diff --git a/services/news-collector/tests/test_main.py b/services/news-collector/tests/test_main.py
index 3ebb094..66190dc 100644
--- a/services/news-collector/tests/test_main.py
+++ b/services/news-collector/tests/test_main.py
@@ -1,5 +1,5 @@
"""Tests for news collector scheduler."""
-import pytest
+
from unittest.mock import AsyncMock, MagicMock
from datetime import datetime, timezone
from shared.models import NewsCategory, NewsItem
@@ -8,9 +8,11 @@ from news_collector.main import run_collector_once
async def test_run_collector_once_stores_and_publishes():
mock_item = NewsItem(
- source="test", headline="Test news",
+ source="test",
+ headline="Test news",
published_at=datetime(2026, 4, 2, tzinfo=timezone.utc),
- sentiment=0.5, category=NewsCategory.MACRO,
+ sentiment=0.5,
+ category=NewsCategory.MACRO,
)
mock_collector = MagicMock()
mock_collector.name = "test"
diff --git a/services/news-collector/tests/test_reddit.py b/services/news-collector/tests/test_reddit.py
index 3626c0a..440b173 100644
--- a/services/news-collector/tests/test_reddit.py
+++ b/services/news-collector/tests/test_reddit.py
@@ -1,33 +1,63 @@
"""Tests for Reddit collector."""
+
import pytest
from unittest.mock import AsyncMock, patch
from news_collector.collectors.reddit import RedditCollector
+
@pytest.fixture
def collector():
return RedditCollector()
+
def test_collector_name(collector):
assert collector.name == "reddit"
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 = [
- {"data": {"title": "NVDA to the moon! AI demand is insane", "selftext": "Just loaded up on NVDA calls", "url": "https://reddit.com/r/wallstreetbets/123", "created_utc": 1711929600, "score": 500, "num_comments": 200, "subreddit": "wallstreetbets"}},
+ {
+ "data": {
+ "title": "NVDA to the moon! AI demand is insane",
+ "selftext": "Just loaded up on NVDA calls",
+ "url": "https://reddit.com/r/wallstreetbets/123",
+ "created_utc": 1711929600,
+ "score": 500,
+ "num_comments": 200,
+ "subreddit": "wallstreetbets",
+ }
+ },
]
- with patch.object(collector, "_fetch_subreddit", new_callable=AsyncMock, return_value=mock_posts):
+ with patch.object(
+ collector, "_fetch_subreddit", new_callable=AsyncMock, return_value=mock_posts
+ ):
items = await collector.collect()
assert len(items) >= 1
assert items[0].source == "reddit"
assert items[0].category.value == "social"
+
async def test_collect_filters_low_score(collector):
mock_posts = [
- {"data": {"title": "Random question", "selftext": "", "url": "https://reddit.com/456", "created_utc": 1711929600, "score": 3, "num_comments": 1, "subreddit": "stocks"}},
+ {
+ "data": {
+ "title": "Random question",
+ "selftext": "",
+ "url": "https://reddit.com/456",
+ "created_utc": 1711929600,
+ "score": 3,
+ "num_comments": 1,
+ "subreddit": "stocks",
+ }
+ },
]
- with patch.object(collector, "_fetch_subreddit", new_callable=AsyncMock, return_value=mock_posts):
+ with patch.object(
+ collector, "_fetch_subreddit", new_callable=AsyncMock, return_value=mock_posts
+ ):
items = await collector.collect()
assert items == []
diff --git a/services/news-collector/tests/test_rss.py b/services/news-collector/tests/test_rss.py
index 58c5f7c..e03250a 100644
--- a/services/news-collector/tests/test_rss.py
+++ b/services/news-collector/tests/test_rss.py
@@ -2,7 +2,6 @@
import pytest
from unittest.mock import AsyncMock, patch
-from datetime import datetime, timezone
from news_collector.collectors.rss import RSSCollector
diff --git a/services/news-collector/tests/test_sec_edgar.py b/services/news-collector/tests/test_sec_edgar.py
index a10b47a..5d4f69f 100644
--- a/services/news-collector/tests/test_sec_edgar.py
+++ b/services/news-collector/tests/test_sec_edgar.py
@@ -40,7 +40,9 @@ async def test_collect_parses_filings(collector):
mock_datetime.now.return_value = datetime(2026, 4, 2, tzinfo=timezone.utc)
mock_datetime.strptime = datetime.strptime
- with patch.object(collector, "_fetch_recent_filings", new_callable=AsyncMock, return_value=[mock_response]):
+ with patch.object(
+ collector, "_fetch_recent_filings", new_callable=AsyncMock, return_value=[mock_response]
+ ):
with patch("news_collector.collectors.sec_edgar.datetime", mock_datetime):
items = await collector.collect()
diff --git a/services/news-collector/tests/test_truth_social.py b/services/news-collector/tests/test_truth_social.py
index bcf8a8c..91ddb9d 100644
--- a/services/news-collector/tests/test_truth_social.py
+++ b/services/news-collector/tests/test_truth_social.py
@@ -1,22 +1,32 @@
"""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": "<p>We are imposing 25% tariffs on all steel imports!</p>", "created_at": "2026-04-02T12:00:00.000Z", "url": "https://truthsocial.com/@realDonaldTrump/12345", "id": "12345"},
+ {
+ "content": "<p>We are imposing 25% tariffs on all steel imports!</p>",
+ "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()
@@ -24,6 +34,7 @@ async def test_collect_parses_posts(collector):
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()