feat: apply rel-001 feedback cleanup
This commit is contained in:
@@ -18,6 +18,31 @@ def test_healthcheck() -> None:
|
||||
assert body["service"] == "portfolio-hub"
|
||||
assert "version" in body
|
||||
assert "checked_at" in body
|
||||
assert "db_enabled" in body
|
||||
assert isinstance(body["db_enabled"], bool)
|
||||
|
||||
|
||||
def test_health_exposes_db_enabled_true(monkeypatch) -> None:
|
||||
"""REQ-035 AC-1: PORTFOLIOHUB_DB_ENABLED=true → db_enabled: true."""
|
||||
monkeypatch.setenv("PORTFOLIOHUB_DB_ENABLED", "true")
|
||||
monkeypatch.setenv("CREDENTIAL_ENCRYPTION_KEY", "test-key-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=")
|
||||
get_settings.cache_clear()
|
||||
client = TestClient(create_app())
|
||||
response = client.get("/health")
|
||||
get_settings.cache_clear()
|
||||
assert response.status_code == 200
|
||||
assert response.json()["db_enabled"] is True
|
||||
|
||||
|
||||
def test_health_exposes_db_enabled_false(monkeypatch) -> None:
|
||||
"""REQ-035 AC-2: PORTFOLIOHUB_DB_ENABLED=false → db_enabled: false."""
|
||||
monkeypatch.setenv("PORTFOLIOHUB_DB_ENABLED", "false")
|
||||
get_settings.cache_clear()
|
||||
client = TestClient(create_app())
|
||||
response = client.get("/health")
|
||||
get_settings.cache_clear()
|
||||
assert response.status_code == 200
|
||||
assert response.json()["db_enabled"] is False
|
||||
|
||||
|
||||
def test_docs_are_exposed() -> None:
|
||||
|
||||
@@ -283,3 +283,35 @@ def test_post_auth_tokens_returns_404(monkeypatch) -> None:
|
||||
|
||||
_app.dependency_overrides.clear()
|
||||
assert response.status_code in (404, 405)
|
||||
|
||||
|
||||
# REQ-034: LoginRequest extra="forbid" enforcement (dcy-005 FR-2)
|
||||
|
||||
def test_login_rejects_no_expiry_extra_field(monkeypatch) -> None:
|
||||
"""REQ-034 AC-2: session 발급 경로에 no_expiry 시도 → HTTP 422 (extra="forbid")."""
|
||||
monkeypatch.setenv("PORTFOLIOHUB_DB_ENABLED", "false")
|
||||
get_settings.cache_clear()
|
||||
client = TestClient(app)
|
||||
|
||||
resp = client.post(
|
||||
"/auth/login",
|
||||
json={"username": "anyone", "password": "any", "no_expiry": True},
|
||||
)
|
||||
|
||||
assert resp.status_code == 422
|
||||
body = resp.json()
|
||||
assert any("extra" in (err.get("type") or "") for err in body.get("detail", []))
|
||||
|
||||
|
||||
def test_login_rejects_arbitrary_extra_field(monkeypatch) -> None:
|
||||
"""REQ-034 AC-3: 임의 추가 필드 → HTTP 422 (extra="forbid" 일반 동작)."""
|
||||
monkeypatch.setenv("PORTFOLIOHUB_DB_ENABLED", "false")
|
||||
get_settings.cache_clear()
|
||||
client = TestClient(app)
|
||||
|
||||
resp = client.post(
|
||||
"/auth/login",
|
||||
json={"username": "anyone", "password": "any", "arbitrary_field": "x"},
|
||||
)
|
||||
|
||||
assert resp.status_code == 422
|
||||
|
||||
@@ -213,7 +213,7 @@ def test_ledger_trade_201_when_daemon_matches(monkeypatch) -> None:
|
||||
portfolio = _portfolio_with_daemon(daemon_id="d-1")
|
||||
trade = MagicMock()
|
||||
trade.ledger_entry_id = 1
|
||||
trade.asset_id = "asset-1"
|
||||
trade.portfolio_id = "asset-1"
|
||||
trade.order_id = "ord-1"
|
||||
trade.execution_id = "exec-1"
|
||||
trade.side = "buy"
|
||||
|
||||
+2
-2
@@ -359,7 +359,7 @@ def _trade_payload(**overrides) -> dict:
|
||||
def _make_ledger_trade(**kwargs) -> LedgerTrade:
|
||||
defaults = dict(
|
||||
ledger_entry_id=1,
|
||||
asset_id="005930",
|
||||
portfolio_id="005930",
|
||||
order_id="ord-001",
|
||||
execution_id="exec-001",
|
||||
side="buy",
|
||||
@@ -411,7 +411,7 @@ def test_v1_ledger_trade_created(monkeypatch) -> None:
|
||||
assert resp.status_code == 201
|
||||
body = resp.json()
|
||||
assert body["status"] == "new"
|
||||
assert body["asset_id"] == "005930"
|
||||
assert body["portfolio_id"] == "005930"
|
||||
|
||||
|
||||
def test_v1_ledger_trade_idempotent_same_payload(monkeypatch) -> None:
|
||||
|
||||
@@ -58,7 +58,7 @@ def _make_portfolio(
|
||||
def _make_trade(**kwargs) -> LedgerTrade:
|
||||
defaults = dict(
|
||||
ledger_entry_id=1,
|
||||
asset_id=_PORTFOLIO_ID,
|
||||
portfolio_id=_PORTFOLIO_ID,
|
||||
order_id="ord-001",
|
||||
execution_id="exec-001",
|
||||
side="buy",
|
||||
@@ -130,7 +130,7 @@ def test_ledger_trade_new() -> None:
|
||||
assert resp.status_code == 201
|
||||
body = resp.json()
|
||||
assert body["status"] == "new"
|
||||
assert body["asset_id"] == _PORTFOLIO_ID
|
||||
assert body["portfolio_id"] == _PORTFOLIO_ID
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user