"""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 == []