test: cover KIS pagination consumer seams
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import replace
|
||||
from unittest.mock import Mock
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -26,11 +27,6 @@ class FakeBroker:
|
||||
return list(self._b)
|
||||
|
||||
|
||||
class FailingBroker(FakeBroker):
|
||||
def get_balance(self):
|
||||
raise BrokerBalanceError("malformed_response")
|
||||
|
||||
|
||||
def _hold(repo, svc, pid, symbol, qty):
|
||||
repo.reconcile_universe(INST, {pid: "SYM"})
|
||||
slot = repo.find_slot_by_portfolio(INST, pid)
|
||||
@@ -84,19 +80,24 @@ def test_ok_when_qty_matches():
|
||||
assert d[str(slot.slot_id)] == "ok"
|
||||
|
||||
|
||||
def test_later_page_snapshot_symbol_keeps_holding_slot_ok():
|
||||
def test_later_page_snapshot_symbol_keeps_holding_slot_ok(kis_balance_broker_factory):
|
||||
repo, svc = _wire()
|
||||
slot = _hold(repo, svc, "pf-later", "000660", 4)
|
||||
broker, calls = kis_balance_broker_factory([
|
||||
{"rows": [], "tr_cont": "F", "fk": "A", "nk": "1"},
|
||||
{"rows": [{"pdno": "000660", "hldg_qty": "4"}], "tr_cont": "E"},
|
||||
])
|
||||
|
||||
decisions = reconcile_core_holdings(
|
||||
slot_repo=repo,
|
||||
slot_service=svc,
|
||||
broker=FakeBroker([BalanceItem(symbol="000660", hldg_qty=4)]),
|
||||
broker=broker,
|
||||
instance_key=INST,
|
||||
)
|
||||
|
||||
assert decisions == {str(slot.slot_id): "ok"}
|
||||
assert repo.fetch_slot(slot.slot_id).status is SlotState.HOLDING
|
||||
assert len(calls) == 2
|
||||
|
||||
|
||||
def test_B_broker_holds_unmanaged_warns():
|
||||
@@ -173,16 +174,39 @@ def test_other_instance_only_managed_slot_remains_unmanaged_position_without_wri
|
||||
assert repo.list_slots(INST) == []
|
||||
|
||||
|
||||
def test_reconcile_core_holdings_propagates_balance_failure_without_slot_write():
|
||||
repo, svc = _wire()
|
||||
def test_reconcile_core_holdings_propagates_later_page_failure_without_write(
|
||||
kis_balance_broker_factory, monkeypatch
|
||||
):
|
||||
repo = TrackingRepository()
|
||||
svc = SlotService(repo, instance_key=INST)
|
||||
slot = _hold(repo, svc, "pf-a", "005930", 10)
|
||||
writes_before = repo.update_calls
|
||||
warn_store = InMemoryReconcileWarningStore()
|
||||
set_warned = Mock(wraps=warn_store.set_warned)
|
||||
clear_warned = Mock(wraps=warn_store.clear_warned)
|
||||
monkeypatch.setattr(warn_store, "set_warned", set_warned)
|
||||
monkeypatch.setattr(warn_store, "clear_warned", clear_warned)
|
||||
broker, calls = kis_balance_broker_factory([
|
||||
{
|
||||
"rows": [{"pdno": "005930", "hldg_qty": "10"}],
|
||||
"tr_cont": "F",
|
||||
"fk": "A",
|
||||
"nk": "1",
|
||||
},
|
||||
{"rows": [], "tr_cont": "X"},
|
||||
])
|
||||
|
||||
with pytest.raises(BrokerBalanceError, match="malformed_response"):
|
||||
reconcile_core_holdings(
|
||||
slot_repo=repo,
|
||||
slot_service=svc,
|
||||
broker=FailingBroker([]),
|
||||
broker=broker,
|
||||
instance_key=INST,
|
||||
warn_store=warn_store,
|
||||
)
|
||||
|
||||
assert len(calls) == 2
|
||||
assert repo.fetch_slot(slot.slot_id).status is SlotState.HOLDING
|
||||
assert repo.update_calls == writes_before
|
||||
set_warned.assert_not_called()
|
||||
clear_warned.assert_not_called()
|
||||
|
||||
Reference in New Issue
Block a user