feat: refactor portfolio strategy references
This commit is contained in:
@@ -13,6 +13,7 @@ def _client_with_tokens() -> TestClient:
|
||||
|
||||
|
||||
def test_read_route_requires_token(monkeypatch) -> None:
|
||||
monkeypatch.setenv("PORTFOLIOHUB_DB_ENABLED", "false")
|
||||
monkeypatch.setenv("PORTFOLIOHUB_READ_TOKENS", "read-token")
|
||||
get_settings.cache_clear()
|
||||
client = _client_with_tokens()
|
||||
@@ -24,6 +25,7 @@ def test_read_route_requires_token(monkeypatch) -> None:
|
||||
|
||||
|
||||
def test_read_route_accepts_read_token(monkeypatch) -> None:
|
||||
monkeypatch.setenv("PORTFOLIOHUB_DB_ENABLED", "false")
|
||||
monkeypatch.setenv("PORTFOLIOHUB_READ_TOKENS", "read-token")
|
||||
get_settings.cache_clear()
|
||||
client = _client_with_tokens()
|
||||
@@ -35,6 +37,7 @@ def test_read_route_accepts_read_token(monkeypatch) -> None:
|
||||
|
||||
|
||||
def test_trade_route_rejects_read_token(monkeypatch) -> None:
|
||||
monkeypatch.setenv("PORTFOLIOHUB_DB_ENABLED", "false")
|
||||
monkeypatch.setenv("PORTFOLIOHUB_READ_TOKENS", "read-token")
|
||||
monkeypatch.setenv("PORTFOLIOHUB_TRADE_WRITE_TOKENS", "trade-token")
|
||||
get_settings.cache_clear()
|
||||
@@ -51,6 +54,7 @@ def test_trade_route_rejects_read_token(monkeypatch) -> None:
|
||||
|
||||
|
||||
def test_admin_route_accepts_admin_token(monkeypatch) -> None:
|
||||
monkeypatch.setenv("PORTFOLIOHUB_DB_ENABLED", "false")
|
||||
monkeypatch.setenv("PORTFOLIOHUB_ADMIN_TOKENS", "admin-token")
|
||||
get_settings.cache_clear()
|
||||
client = _client_with_tokens()
|
||||
|
||||
+11
-12
@@ -39,8 +39,8 @@ class FakeRepo:
|
||||
*,
|
||||
broker: str = "kis",
|
||||
status: str = "enabled",
|
||||
strategy_name: str = "",
|
||||
strategy_params: dict | None = None,
|
||||
active_strategy_id: str | None = None,
|
||||
avabile_strategies: list[str] | None = None,
|
||||
initial_cash: float = 0.0,
|
||||
) -> Portfolio:
|
||||
if self._portfolio is None:
|
||||
@@ -49,9 +49,9 @@ class FakeRepo:
|
||||
broker=broker,
|
||||
status=status,
|
||||
symbol=symbol,
|
||||
strategy_name=strategy_name,
|
||||
strategy_params=strategy_params or {},
|
||||
cash_balance=initial_cash,
|
||||
active_strategy_id=active_strategy_id,
|
||||
avabile_strategies=avabile_strategies,
|
||||
)
|
||||
return self._portfolio
|
||||
|
||||
@@ -62,24 +62,24 @@ class FakeRepo:
|
||||
broker: str,
|
||||
status: str,
|
||||
symbol: str,
|
||||
strategy_name: str,
|
||||
strategy_params: dict,
|
||||
cash_balance: float,
|
||||
asset_quantity: float,
|
||||
asset_price: float,
|
||||
profit_buffer: float,
|
||||
active_strategy_id: str | None,
|
||||
avabile_strategies: list[str] | None,
|
||||
) -> Portfolio:
|
||||
self._portfolio = Portfolio(
|
||||
portfolio_id=portfolio_id,
|
||||
broker=broker,
|
||||
status=status,
|
||||
symbol=symbol,
|
||||
strategy_name=strategy_name,
|
||||
strategy_params=strategy_params,
|
||||
cash_balance=cash_balance,
|
||||
asset_quantity=asset_quantity,
|
||||
price=asset_price,
|
||||
profit_buffer=profit_buffer,
|
||||
active_strategy_id=active_strategy_id,
|
||||
avabile_strategies=avabile_strategies,
|
||||
)
|
||||
return self._portfolio
|
||||
|
||||
@@ -149,7 +149,7 @@ class FakeRepo:
|
||||
portfolio.asset_quantity = 0.0
|
||||
portfolio.price = 0.0
|
||||
portfolio.profit_buffer = 0.0
|
||||
portfolio.current_strategy_set_id = None
|
||||
portfolio.active_strategy_id = None
|
||||
self.entries = []
|
||||
return portfolio
|
||||
|
||||
@@ -194,13 +194,12 @@ def _portfolio() -> Portfolio:
|
||||
broker="kis",
|
||||
status="enabled",
|
||||
symbol="005930",
|
||||
strategy_name="target_value",
|
||||
strategy_params={"target_asset_ratio": 0.7},
|
||||
cash_balance=1_000_000.0,
|
||||
asset_quantity=1.0,
|
||||
price=70_000.0,
|
||||
profit_buffer=50_000.0,
|
||||
current_strategy_set_id="set-1",
|
||||
active_strategy_id="set-1",
|
||||
avabile_strategies=["set-1"],
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -27,8 +27,8 @@ class FakeRepo:
|
||||
*,
|
||||
broker: str = "kis",
|
||||
status: str = "enabled",
|
||||
strategy_name: str = "",
|
||||
strategy_params: dict | None = None,
|
||||
active_strategy_id: str | None = None,
|
||||
avabile_strategies: list[str] | None = None,
|
||||
initial_cash: float = 0.0,
|
||||
) -> Portfolio:
|
||||
self._portfolio = Portfolio(
|
||||
@@ -36,9 +36,9 @@ class FakeRepo:
|
||||
broker=broker,
|
||||
status=status,
|
||||
symbol=symbol,
|
||||
strategy_name=strategy_name,
|
||||
strategy_params=strategy_params or {},
|
||||
cash_balance=initial_cash,
|
||||
active_strategy_id=active_strategy_id,
|
||||
avabile_strategies=avabile_strategies,
|
||||
)
|
||||
return self._portfolio
|
||||
|
||||
@@ -107,7 +107,7 @@ class FakeRepo:
|
||||
portfolio.asset_quantity = 0.0
|
||||
portfolio.price = 0.0
|
||||
portfolio.profit_buffer = 0.0
|
||||
portfolio.current_strategy_set_id = None
|
||||
portfolio.active_strategy_id = None
|
||||
self.entries = []
|
||||
return portfolio
|
||||
|
||||
@@ -146,13 +146,12 @@ def _portfolio() -> Portfolio:
|
||||
broker="kis",
|
||||
status="enabled",
|
||||
symbol="005930",
|
||||
strategy_name="target_value",
|
||||
strategy_params={"target_asset_ratio": 0.7},
|
||||
cash_balance=1_000_000.0,
|
||||
asset_quantity=0.0,
|
||||
price=70_000.0,
|
||||
profit_buffer=0.0,
|
||||
current_strategy_set_id="set-1",
|
||||
active_strategy_id="set-1",
|
||||
avabile_strategies=["set-1"],
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user