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:17:43 +0900
committerTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2026-04-02 14:17:43 +0900
commit35aa61c651217663406c9cd6df404f85338b2d68 (patch)
tree9d85dd87e725984d45d7b6bdfef8b316ddfc4ae7 /services/news-collector/tests/test_reddit.py
parent17540c99d5e28576a6642e23d7bd6b297513e2d8 (diff)
style: fix lint and formatting issues across news collector and shared
Diffstat (limited to 'services/news-collector/tests/test_reddit.py')
-rw-r--r--services/news-collector/tests/test_reddit.py38
1 files changed, 34 insertions, 4 deletions
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 == []