test: cover KIS pagination consumer seams
This commit is contained in:
@@ -14,6 +14,8 @@ import os
|
||||
|
||||
import pytest
|
||||
|
||||
from trex_core.adapters.broker.kis import KISBroker
|
||||
|
||||
_PG_TABLES = (
|
||||
"broker_account_snapshot",
|
||||
"killswitch_exclusion",
|
||||
@@ -26,6 +28,53 @@ _PG_TABLES = (
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def kis_balance_broker_factory(monkeypatch):
|
||||
"""Build a real KISBroker backed by deterministic synthetic balance pages."""
|
||||
|
||||
def factory(responses):
|
||||
broker = KISBroker(
|
||||
"12345678-01",
|
||||
app_key="test-app-key",
|
||||
app_secret="test-app-secret",
|
||||
base_url="https://openapivts.kis.test",
|
||||
)
|
||||
monkeypatch.setattr(broker, "_headers", lambda _tr: {})
|
||||
pending = list(responses)
|
||||
calls = []
|
||||
|
||||
class Response:
|
||||
def __init__(self, page):
|
||||
self._page = page
|
||||
self.headers = {"tr_cont": page.get("tr_cont", "E")}
|
||||
|
||||
def raise_for_status(self):
|
||||
return None
|
||||
|
||||
def json(self):
|
||||
return {
|
||||
"rt_cd": self._page.get("rt_cd", "0"),
|
||||
"output1": self._page.get("rows", []),
|
||||
"ctx_area_fk100": self._page.get("fk", ""),
|
||||
"ctx_area_nk100": self._page.get("nk", ""),
|
||||
}
|
||||
|
||||
def fake_get(*_args, **kwargs):
|
||||
calls.append({
|
||||
"headers": dict(kwargs["headers"]),
|
||||
"params": dict(kwargs["params"]),
|
||||
})
|
||||
response = pending.pop(0)
|
||||
if isinstance(response, BaseException):
|
||||
raise response
|
||||
return Response(response)
|
||||
|
||||
monkeypatch.setattr("trex_core.adapters.broker.kis.httpx.get", fake_get)
|
||||
return broker, calls
|
||||
|
||||
return factory
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def pg_dsn() -> str:
|
||||
dsn = os.environ.get("TREX_POSTGRESQL_TEST_DSN")
|
||||
|
||||
Reference in New Issue
Block a user