trading/tests/services/kevin_signal_bridge/test_risk_counters.py
Viktor Barzin a417cae77b
Some checks failed
ci/woodpecker/push/woodpecker Pipeline was canceled
feat(kevin_bridge): blocklist + daily risk counters
2026-05-24 01:01:54 +00:00

55 lines
1.6 KiB
Python

"""Tests for KevinRiskCounters using fakeredis."""
from decimal import Decimal
import fakeredis.aioredis
from services.kevin_signal_bridge.risk_counters import KevinRiskCounters
async def _redis():
return fakeredis.aioredis.FakeRedis()
async def test_get_daily_trades_starts_at_zero():
rc = KevinRiskCounters(await _redis())
assert await rc.get_daily_trades() == 0
async def test_increment_daily_trades_increments():
rc = KevinRiskCounters(await _redis())
n = await rc.increment_daily_trades()
assert n == 1
n2 = await rc.increment_daily_trades()
assert n2 == 2
assert await rc.get_daily_trades() == 2
async def test_get_daily_alloc_starts_at_zero():
rc = KevinRiskCounters(await _redis())
assert await rc.get_daily_alloc() == Decimal("0")
async def test_add_daily_alloc_accumulates():
rc = KevinRiskCounters(await _redis())
await rc.add_daily_alloc(Decimal("1000"))
new = await rc.add_daily_alloc(Decimal("2500"))
assert new == Decimal("3500")
assert await rc.get_daily_alloc() == Decimal("3500")
async def test_pause_flag_default_false():
rc = KevinRiskCounters(await _redis())
assert await rc.is_trading_paused() is False
async def test_set_trading_paused_with_ttl_sets_flag():
rc = KevinRiskCounters(await _redis())
await rc.set_trading_paused(ttl_seconds=60)
assert await rc.is_trading_paused() is True
async def test_set_trading_paused_permanent_sets_flag():
rc = KevinRiskCounters(await _redis())
await rc.set_trading_paused()
assert await rc.is_trading_paused() is True