"""R7: DELETE /trades/pending(+v2) 는 PENDING 을 지우지 않는다 (원장 BUY 합계·강등 방어 근거).""" import pytest from types import SimpleNamespace class _Res: def __init__(self, rows): self._rows = rows def scalars(self): return SimpleNamespace(all=lambda: self._rows) class _DB: def __init__(self): self.stmts, self.deleted = [], [] async def execute(self, stmt): self.stmts.append(stmt) return _Res([]) async def delete(self, obj): self.deleted.append(obj) async def commit(self): return None def _params(stmt): return [str(v) for v in stmt.compile().params.values()] @pytest.mark.asyncio async def test_v1_only_failed_before_today(): from app.api.endpoints import trades as tr db = _DB() await tr.delete_pending_trades(db=db) p = _params(db.stmts[0]) assert "FAILED" in p and "PENDING" not in p assert "created_at <" in str(db.stmts[0].compile()) @pytest.mark.asyncio async def test_v2_only_failed_before_today(monkeypatch): from app.api.endpoints import trades_v2 as t2 async def _uid(*a, **k): return None monkeypatch.setattr(t2, "_resolve_target_user_id", _uid) db = _DB() await t2.delete_pending_trades_v2(user=SimpleNamespace(), db=db) p = _params(db.stmts[0]) assert "FAILED" in p and "PENDING" not in p assert "created_at <" in str(db.stmts[0].compile())