feat(screener): POST /snapshot/refresh-news-sentiment with telegram_text
This commit is contained in:
36
stock-lab/tests/test_ai_news_router.py
Normal file
36
stock-lab/tests/test_ai_news_router.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import datetime as dt
|
||||
from unittest.mock import AsyncMock, patch
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from app.main import app
|
||||
|
||||
|
||||
def test_refresh_news_sentiment_weekend_skip():
|
||||
# 2026-05-16 = Saturday
|
||||
client = TestClient(app)
|
||||
resp = client.post(
|
||||
"/api/stock/screener/snapshot/refresh-news-sentiment?asof=2026-05-16"
|
||||
)
|
||||
assert resp.status_code == 200
|
||||
assert resp.json()["status"] == "skipped_weekend"
|
||||
|
||||
|
||||
def test_refresh_news_sentiment_weekday_invokes_pipeline():
|
||||
fake_summary = {
|
||||
"asof": "2026-05-13", "updated": 3, "failures": [],
|
||||
"duration_sec": 1.0, "tokens_input": 100, "tokens_output": 20,
|
||||
"top_pos": [], "top_neg": [], "model": "m",
|
||||
}
|
||||
with patch("app.screener.router._ai_pipeline") as mp, \
|
||||
patch("app.screener.router._ai_telegram") as mt:
|
||||
mp.refresh_daily = AsyncMock(return_value=fake_summary)
|
||||
mt.build_message = lambda **kw: "BUILT_TEXT"
|
||||
client = TestClient(app)
|
||||
resp = client.post(
|
||||
"/api/stock/screener/snapshot/refresh-news-sentiment?asof=2026-05-13"
|
||||
)
|
||||
assert resp.status_code == 200
|
||||
body = resp.json()
|
||||
assert body["asof"] == "2026-05-13"
|
||||
assert body["updated"] == 3
|
||||
assert body["telegram_text"] == "BUILT_TEXT"
|
||||
Reference in New Issue
Block a user