1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
"""Tests for RSS news collector."""
import pytest
from unittest.mock import AsyncMock, patch
from news_collector.collectors.rss import RSSCollector
@pytest.fixture
def collector():
return RSSCollector()
def test_collector_name(collector):
assert collector.name == "rss"
assert collector.poll_interval == 600
async def test_is_available(collector):
assert await collector.is_available() is True
async def test_collect_parses_feed(collector):
mock_feed = {
"entries": [
{
"title": "NVDA surges on AI demand",
"link": "https://example.com/nvda",
"published_parsed": (2026, 4, 2, 12, 0, 0, 0, 0, 0),
"summary": "Nvidia stock jumped 5%...",
},
{
"title": "Markets rally on jobs data",
"link": "https://example.com/market",
"published_parsed": (2026, 4, 2, 11, 0, 0, 0, 0, 0),
"summary": "The S&P 500 rose...",
},
],
}
with patch.object(collector, "_fetch_feeds", new_callable=AsyncMock, return_value=[mock_feed]):
items = await collector.collect()
assert len(items) == 2
assert items[0].source == "rss"
assert items[0].headline == "NVDA surges on AI demand"
assert isinstance(items[0].sentiment, float)
|