test: cover unmanaged position lifecycle flow
Co-authored-by: genichin <4282227+genichin@users.noreply.github.com>
This commit is contained in:
co-authored by
genichin
parent
fe51d211d9
commit
f2b825e720
@@ -32,7 +32,7 @@ class FakeBroker:
|
||||
|
||||
class RaisingBroker(FakeBroker):
|
||||
def get_balance(self):
|
||||
raise BrokerBalanceError("broker_unavailable")
|
||||
raise BrokerBalanceError("transport_failed")
|
||||
|
||||
|
||||
def _wire():
|
||||
|
||||
+2
-3
@@ -96,7 +96,6 @@ def pg_clean(pg_dsn: str):
|
||||
from trex_core.adapters.persistence.migrate import apply_migrations
|
||||
|
||||
apply_migrations(pg_dsn)
|
||||
with psycopg.connect(pg_dsn, autocommit=True) as conn:
|
||||
with conn.cursor() as cur:
|
||||
cur.execute(f"TRUNCATE {', '.join(_PG_TABLES)}")
|
||||
with psycopg.connect(pg_dsn, autocommit=True) as conn, conn.cursor() as cur:
|
||||
cur.execute(f"TRUNCATE {', '.join(_PG_TABLES)}")
|
||||
return pg_dsn
|
||||
|
||||
@@ -383,10 +383,13 @@ def test_sync_requires_yes_when_not_dry_run(capsys, monkeypatch):
|
||||
"""sync without --yes (and not dry-run) should abort."""
|
||||
def _fake_sync(args, cfg, confirm):
|
||||
# Simulate the confirmation prompt returning False (no --yes, interactive aborts)
|
||||
if not getattr(args, "dry_run", False) and not getattr(args, "yes", False):
|
||||
if not confirm("Sync?"):
|
||||
print("aborted")
|
||||
return 1
|
||||
if (
|
||||
not getattr(args, "dry_run", False)
|
||||
and not getattr(args, "yes", False)
|
||||
and not confirm("Sync?")
|
||||
):
|
||||
print("aborted")
|
||||
return 1
|
||||
return 0
|
||||
monkeypatch.setattr(cli, "_cmd_sync", _fake_sync)
|
||||
rc = cli.main(["sync", "--portfolio-id", "PF-1"], confirm=lambda _: False)
|
||||
@@ -398,7 +401,7 @@ def test_sync_live_requires_live_flag(capsys, monkeypatch):
|
||||
monkeypatch.setattr(cli, "_broker_mode", lambda cfg: ("kis", True))
|
||||
|
||||
def _fake_sync(args, cfg, confirm):
|
||||
broker, is_live = cli._broker_mode(cfg)
|
||||
_broker, is_live = cli._broker_mode(cfg)
|
||||
if is_live and not getattr(args, "live", False):
|
||||
cli._fail("live account requires --live (with --yes) to confirm a real sync", args.json)
|
||||
return 2
|
||||
@@ -415,7 +418,7 @@ def test_sync_fail_closed_skipped_error_exits_nonzero_without_writes(
|
||||
"""REQ-123: a fail-closed skipped live sync is a CLI failure."""
|
||||
class _Provider:
|
||||
def get_broker_for_read(self):
|
||||
return SimpleNamespace(get_balance=lambda: []), None
|
||||
return SimpleNamespace(get_balance=list), None
|
||||
|
||||
class _WarningStore:
|
||||
def clear_warned(self, *_args):
|
||||
@@ -452,7 +455,7 @@ def test_sync_fail_closed_skipped_error_exits_nonzero_without_writes(
|
||||
}
|
||||
|
||||
psycopg = types.ModuleType("psycopg")
|
||||
setattr(psycopg, "connect", lambda *_args, **_kwargs: _Connection())
|
||||
psycopg.connect = lambda *_args, **_kwargs: _Connection()
|
||||
monkeypatch.setitem(sys.modules, "psycopg", psycopg)
|
||||
monkeypatch.setattr("trex_core.runtime.broker_provider.build_broker_provider", lambda _cfg: _Provider())
|
||||
monkeypatch.setattr("trex_core.adapters.portfolio.reconcile_warning_store.PostgreSQLReconcileWarningStore", lambda *_args: _WarningStore())
|
||||
@@ -707,10 +710,10 @@ def test_verify_cmd_broker_import_does_not_raise(monkeypatch):
|
||||
|
||||
# Patch at module level — _cmd_verify uses local `from ... import` so we
|
||||
# must patch the source module, not the cli namespace.
|
||||
import trex_core.adapters.persistence.postgresql as pg_mod
|
||||
import trex_core.adapters.portfolio.reconcile_warning_store as rws_mod
|
||||
from trex_core.application.portfolio import InMemoryReconcileWarningStore
|
||||
from trex_core.domain.slot.in_memory_repository import InMemorySlotRepository
|
||||
import trex_core.adapters.portfolio.reconcile_warning_store as rws_mod
|
||||
import trex_core.adapters.persistence.postgresql as pg_mod
|
||||
|
||||
monkeypatch.setattr(rws_mod, "PostgreSQLReconcileWarningStore",
|
||||
lambda dsn: InMemoryReconcileWarningStore())
|
||||
|
||||
Reference in New Issue
Block a user