test: add E2E tests for KJB strategy, backtest, and signal endpoints
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
3c969fc53c
commit
5268d1fa60
74
backend/tests/e2e/test_kjb_flow.py
Normal file
74
backend/tests/e2e/test_kjb_flow.py
Normal file
@ -0,0 +1,74 @@
|
||||
"""
|
||||
E2E tests for KJB strategy flow.
|
||||
"""
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
|
||||
def test_kjb_strategy_endpoint(client: TestClient, auth_headers):
|
||||
"""Test KJB strategy ranking endpoint."""
|
||||
response = client.post(
|
||||
"/api/strategy/kjb",
|
||||
json={
|
||||
"universe": {"markets": ["KOSPI"]},
|
||||
"top_n": 10,
|
||||
},
|
||||
headers=auth_headers,
|
||||
)
|
||||
assert response.status_code in [200, 400, 500]
|
||||
if response.status_code == 200:
|
||||
data = response.json()
|
||||
assert data["strategy_name"] == "kjb"
|
||||
assert "stocks" in data
|
||||
|
||||
|
||||
def test_kjb_backtest_creation(client: TestClient, auth_headers):
|
||||
"""Test creating a KJB backtest."""
|
||||
response = client.post(
|
||||
"/api/backtest",
|
||||
json={
|
||||
"strategy_type": "kjb",
|
||||
"strategy_params": {
|
||||
"max_positions": 10,
|
||||
"cash_reserve_ratio": 0.3,
|
||||
"stop_loss_pct": 0.03,
|
||||
"target1_pct": 0.05,
|
||||
"target2_pct": 0.10,
|
||||
},
|
||||
"start_date": "2023-01-01",
|
||||
"end_date": "2023-12-31",
|
||||
"initial_capital": 10000000,
|
||||
"commission_rate": 0.00015,
|
||||
"slippage_rate": 0.001,
|
||||
"benchmark": "KOSPI",
|
||||
"top_n": 30,
|
||||
},
|
||||
headers=auth_headers,
|
||||
)
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert "id" in data
|
||||
assert data["status"] == "pending"
|
||||
|
||||
|
||||
def test_signal_today_endpoint(client: TestClient, auth_headers):
|
||||
"""Test today's signals endpoint."""
|
||||
response = client.get("/api/signal/kjb/today", headers=auth_headers)
|
||||
assert response.status_code == 200
|
||||
assert isinstance(response.json(), list)
|
||||
|
||||
|
||||
def test_signal_history_endpoint(client: TestClient, auth_headers):
|
||||
"""Test signal history endpoint."""
|
||||
response = client.get(
|
||||
"/api/signal/kjb/history",
|
||||
params={"limit": 10},
|
||||
headers=auth_headers,
|
||||
)
|
||||
assert response.status_code == 200
|
||||
assert isinstance(response.json(), list)
|
||||
|
||||
|
||||
def test_signal_requires_auth(client: TestClient):
|
||||
"""Test that signal endpoints require authentication."""
|
||||
response = client.get("/api/signal/kjb/today")
|
||||
assert response.status_code == 401
|
||||
Loading…
x
Reference in New Issue
Block a user