fix(agent-office): bookmark field name + service_proxy contract + mktemp

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-28 09:09:05 +09:00
parent 7b3ddd1b19
commit 1d6c1b4329
4 changed files with 23 additions and 14 deletions

View File

@@ -112,13 +112,15 @@ async def realestate_collect() -> Dict[str, Any]:
async def realestate_matches(limit: int = 20) -> List[Dict[str, Any]]: async def realestate_matches(limit: int = 20) -> List[Dict[str, Any]]:
resp = await _client.get( """realestate-lab의 GET /api/realestate/matches 호출."""
async with httpx.AsyncClient(timeout=10) as client:
resp = await client.get(
f"{REALESTATE_LAB_URL}/api/realestate/matches", f"{REALESTATE_LAB_URL}/api/realestate/matches",
params={"limit": limit, "unread_only": True}, params={"size": limit},
) )
resp.raise_for_status() resp.raise_for_status()
data = resp.json() data = resp.json()
return data if isinstance(data, list) else data.get("matches", []) return data.get("items", [])
async def realestate_dashboard() -> Dict[str, Any]: async def realestate_dashboard() -> Dict[str, Any]:

View File

@@ -84,10 +84,10 @@ async def _handle_realestate_bookmark(callback_query: dict, callback_id: str) ->
try: try:
result = await service_proxy.realestate_bookmark_toggle(ann_id) result = await service_proxy.realestate_bookmark_toggle(ann_id)
bookmarked = result.get("bookmarked", None) is_on = result.get("is_bookmarked")
if bookmarked is True: if is_on == 1:
await send_raw(f"🔖 북마크 추가 완료 (#{ann_id})") await send_raw(f"🔖 북마크 추가 완료 (#{ann_id})")
elif bookmarked is False: elif is_on == 0:
await send_raw(f"🔖 북마크 해제 완료 (#{ann_id})") await send_raw(f"🔖 북마크 해제 완료 (#{ann_id})")
else: else:
await send_raw(f"🔖 북마크 토글 완료 (#{ann_id})") await send_raw(f"🔖 북마크 토글 완료 (#{ann_id})")

View File

@@ -2,7 +2,9 @@ import os
import sys import sys
import tempfile import tempfile
_TMP = tempfile.mktemp(suffix=".db") _fd, _TMP = tempfile.mkstemp(suffix=".db")
os.close(_fd)
os.unlink(_TMP)
os.environ["AGENT_OFFICE_DB_PATH"] = _TMP os.environ["AGENT_OFFICE_DB_PATH"] = _TMP
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

View File

@@ -4,7 +4,9 @@ import tempfile
import gc import gc
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
_TMP = tempfile.mktemp(suffix=".db") _fd, _TMP = tempfile.mkstemp(suffix=".db")
os.close(_fd)
os.unlink(_TMP)
os.environ["AGENT_OFFICE_DB_PATH"] = _TMP os.environ["AGENT_OFFICE_DB_PATH"] = _TMP
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
@@ -26,11 +28,12 @@ def _init_db():
def test_callback_realestate_bookmark_calls_proxy(): def test_callback_realestate_bookmark_calls_proxy():
"""callback_data 'realestate_bookmark_42' 가 service_proxy.realestate_bookmark_toggle(42) 를 호출.""" """callback_data 'realestate_bookmark_42' 가 service_proxy.realestate_bookmark_toggle(42) 를 호출하고
is_bookmarked=1 이면 '추가 완료' 메시지를 전송한다."""
from app import service_proxy from app import service_proxy
from app.telegram import webhook from app.telegram import webhook
fake_toggle = AsyncMock(return_value={"bookmarked": True}) fake_toggle = AsyncMock(return_value={"is_bookmarked": 1})
fake_send = AsyncMock(return_value={"ok": True}) fake_send = AsyncMock(return_value={"ok": True})
fake_api_call = AsyncMock(return_value={"ok": True}) fake_api_call = AsyncMock(return_value={"ok": True})
@@ -49,6 +52,8 @@ def test_callback_realestate_bookmark_calls_proxy():
fake_toggle.assert_awaited_once_with(42) fake_toggle.assert_awaited_once_with(42)
assert result == {"ok": True, "announcement_id": 42} assert result == {"ok": True, "announcement_id": 42}
args, _ = fake_send.call_args
assert "추가" in args[0]
def test_callback_realestate_bookmark_invalid_id(): def test_callback_realestate_bookmark_invalid_id():