feat(stock): session 판정 + webai monitor-set 엔드포인트
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EqCYBhvTcdeCTUDX3RhWx9
This commit is contained in:
35
stock/tests/test_trade_alerts_monitorset_api.py
Normal file
35
stock/tests/test_trade_alerts_monitorset_api.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import datetime as dt
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
|
||||
def test_current_session_windows():
|
||||
from app.trade_alerts import current_session
|
||||
d = dt.date(2026, 7, 2)
|
||||
assert current_session(dt.datetime.combine(d, dt.time(8, 40))) == "pre"
|
||||
assert current_session(dt.datetime.combine(d, dt.time(10, 0))) == "regular"
|
||||
assert current_session(dt.datetime.combine(d, dt.time(17, 0))) == "after"
|
||||
assert current_session(dt.datetime.combine(d, dt.time(20, 0))) == "closed"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client(monkeypatch, tmp_path):
|
||||
from app import db as _db
|
||||
monkeypatch.setattr(_db, "DB_PATH", str(tmp_path / "stock.db"))
|
||||
_db.init_db()
|
||||
monkeypatch.setenv("WEBAI_API_KEY", "k")
|
||||
from app.main import app
|
||||
return TestClient(app)
|
||||
|
||||
|
||||
def test_monitor_set_requires_auth(client):
|
||||
assert client.get("/api/webai/trade-alert/monitor-set").status_code == 401
|
||||
|
||||
|
||||
def test_monitor_set_ok(client):
|
||||
r = client.get("/api/webai/trade-alert/monitor-set", headers={"X-WebAI-Key": "k"})
|
||||
assert r.status_code == 200
|
||||
body = r.json()
|
||||
assert body["session"] in ("pre", "regular", "after", "closed")
|
||||
assert "buy_targets" in body and "sell_targets" in body
|
||||
assert body["exit_params"]["trailing_pct"] == 0.10
|
||||
Reference in New Issue
Block a user