summaryrefslogtreecommitdiff
path: root/services/news-collector/tests/test_sec_edgar.py
blob: 5d4f69f0698d2d4a95726e53f44dec71c88fa9db (plain)
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
48
49
50
51
52
53
54
55
56
57
58
"""Tests for SEC EDGAR filing collector."""

import pytest
from datetime import datetime, timezone
from unittest.mock import AsyncMock, patch, MagicMock

from news_collector.collectors.sec_edgar import SecEdgarCollector


@pytest.fixture
def collector():
    return SecEdgarCollector()


def test_collector_name(collector):
    assert collector.name == "sec_edgar"
    assert collector.poll_interval == 1800


async def test_is_available(collector):
    assert await collector.is_available() is True


async def test_collect_parses_filings(collector):
    mock_response = {
        "filings": {
            "recent": {
                "accessionNumber": ["0001234-26-000001"],
                "filingDate": ["2026-04-02"],
                "primaryDocument": ["filing.htm"],
                "form": ["8-K"],
                "primaryDocDescription": ["Current Report"],
            }
        },
        "tickers": [{"ticker": "AAPL"}],
        "name": "Apple Inc",
    }

    mock_datetime = MagicMock(spec=datetime)
    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("news_collector.collectors.sec_edgar.datetime", mock_datetime):
            items = await collector.collect()

    assert len(items) == 1
    assert items[0].source == "sec_edgar"
    assert items[0].category.value == "filing"
    assert "AAPL" in items[0].symbols


async def test_collect_handles_empty(collector):
    with patch.object(collector, "_fetch_recent_filings", new_callable=AsyncMock, return_value=[]):
        items = await collector.collect()
    assert items == []