feat(CORE-001D3A): normalize alerts and settings service boundaries
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from decimal import Decimal
|
||||
|
||||
import pytest
|
||||
|
||||
from app.models.portfolio import PortfolioConfig
|
||||
from app.services.settings_status import save_status_text
|
||||
from app.services.settings_status import _normalize_save_status_snapshot, save_status_text
|
||||
|
||||
|
||||
class CallableMarginCallPriceConfig:
|
||||
@@ -17,6 +21,34 @@ class CallableMarginCallPriceConfig:
|
||||
return self._margin_call_price
|
||||
|
||||
|
||||
class StringBoundaryConfig:
|
||||
entry_basis_mode = "weight"
|
||||
gold_value = "215000"
|
||||
entry_price = "215.0"
|
||||
gold_ounces = "1000"
|
||||
current_ltv = "0.6744186046511628"
|
||||
margin_call_price = "193.33333333333334"
|
||||
|
||||
|
||||
def test_normalize_save_status_snapshot_coerces_numeric_boundary_values() -> None:
|
||||
snapshot = _normalize_save_status_snapshot(StringBoundaryConfig())
|
||||
|
||||
assert snapshot.entry_basis_mode == "weight"
|
||||
assert snapshot.gold_value == Decimal("215000")
|
||||
assert snapshot.entry_price == Decimal("215.0")
|
||||
assert snapshot.gold_ounces == Decimal("1000")
|
||||
assert snapshot.current_ltv == Decimal("0.6744186046511628")
|
||||
assert snapshot.margin_call_price == Decimal("193.33333333333334")
|
||||
|
||||
|
||||
def test_normalize_save_status_snapshot_rejects_bool_values() -> None:
|
||||
class InvalidBoundaryConfig(StringBoundaryConfig):
|
||||
current_ltv = True
|
||||
|
||||
with pytest.raises(TypeError, match="config.current_ltv must be numeric, got bool"):
|
||||
_normalize_save_status_snapshot(InvalidBoundaryConfig())
|
||||
|
||||
|
||||
def test_save_status_text_uses_margin_call_price_api() -> None:
|
||||
config = PortfolioConfig(gold_value=215_000.0, entry_price=215.0, loan_amount=145_000.0)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user