summaryrefslogtreecommitdiff
path: root/services/news-collector/tests/test_reddit.py
diff options
context:
space:
mode:
authorTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2026-04-02 14:05:21 +0900
committerTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2026-04-02 14:05:21 +0900
commit0f1cb0fcd033aef5c1add796821348507580055b (patch)
tree8ce194f628f38d99bdb264283e8c160ba20a6960 /services/news-collector/tests/test_reddit.py
parent531213bc26c4a455ee604b79f0065df2a3cb4218 (diff)
feat: implement Reddit social sentiment collector
Diffstat (limited to 'services/news-collector/tests/test_reddit.py')
-rw-r--r--services/news-collector/tests/test_reddit.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/services/news-collector/tests/test_reddit.py b/services/news-collector/tests/test_reddit.py
new file mode 100644
index 0000000..3626c0a
--- /dev/null
+++ b/services/news-collector/tests/test_reddit.py
@@ -0,0 +1,33 @@
+"""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"}},
+ ]
+ 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"}},
+ ]
+ with patch.object(collector, "_fetch_subreddit", new_callable=AsyncMock, return_value=mock_posts):
+ items = await collector.collect()
+ assert items == []