Big refactoring
Some checks failed
Deploy / lint (push) Failing after 21s
Deploy / test (push) Has been skipped
Deploy / deploy (push) Has been skipped

This commit is contained in:
Dennis Thiessen
2026-03-03 15:20:18 +01:00
parent 181cfe6588
commit 0a011d4ce9
55 changed files with 6898 additions and 544 deletions

View File

@@ -8,6 +8,7 @@ from unittest.mock import AsyncMock, MagicMock, patch
import pytest
from app.exceptions import ProviderError
from app.providers.openai_sentiment import OpenAISentimentProvider
@@ -160,3 +161,42 @@ class TestCitationsExtraction:
assert result.citations == []
assert result.reasoning == "Quiet day"
class TestBatchSentiment:
@pytest.mark.asyncio
async def test_batch_sentiment_parses_multiple_tickers(self, provider):
json_text = (
'[{"ticker":"AAPL","classification":"bullish","confidence":81,"reasoning":"Positive earnings"},'
'{"ticker":"MSFT","classification":"neutral","confidence":52,"reasoning":"Mixed guidance"}]'
)
mock_response = _build_response(json_text)
provider._client.responses.create = AsyncMock(return_value=mock_response)
result = await provider.fetch_sentiment_batch(["AAPL", "MSFT"])
assert set(result.keys()) == {"AAPL", "MSFT"}
assert result["AAPL"].classification == "bullish"
assert result["MSFT"].classification == "neutral"
@pytest.mark.asyncio
async def test_batch_sentiment_skips_invalid_rows(self, provider):
json_text = (
'[{"ticker":"AAPL","classification":"bullish","confidence":81,"reasoning":"Positive earnings"},'
'{"ticker":"TSLA","classification":"invalid","confidence":95,"reasoning":"Bad shape"}]'
)
mock_response = _build_response(json_text)
provider._client.responses.create = AsyncMock(return_value=mock_response)
result = await provider.fetch_sentiment_batch(["AAPL", "MSFT"])
assert set(result.keys()) == {"AAPL"}
@pytest.mark.asyncio
async def test_batch_sentiment_requires_array_json(self, provider):
json_text = '{"ticker":"AAPL","classification":"bullish","confidence":81,"reasoning":"Positive earnings"}'
mock_response = _build_response(json_text)
provider._client.responses.create = AsyncMock(return_value=mock_response)
with pytest.raises(ProviderError):
await provider.fetch_sentiment_batch(["AAPL", "MSFT"])