"""화면 취향 저장 — 지워진 프로젝트 id 가 박힌 키는 버림 · 나머지 키는 그대로.""" import asyncio import json import B01_Dashboard.B01_Dashboard_Repository as repo LIVE = "226fc805-26c8-4f5a-9956-bacb200e10a5" DEAD = "936be972-11bc-46c2-8bf3-b15d8de7df0d" class _Cursor: def __init__(self, store): self.store = store self.rows = [] async def __aenter__(self): return self async def __aexit__(self, *_): return False async def execute(self, sql, args): if sql.startswith("SELECT id FROM projects"): self.rows = [(i,) for i in args if i == LIVE] else: self.store["saved"] = json.loads(args[1]) async def fetchall(self): return self.rows class _Conn: def __init__(self, store): self.store = store async def __aenter__(self): return self async def __aexit__(self, *_): return False def cursor(self): return _Cursor(self.store) async def commit(self): pass class _Pool: def __init__(self, store): self.store = store def acquire(self): return _Conn(self.store) def test_dead_project_keys_dropped(monkeypatch): store = {} monkeypatch.setattr(repo, "get_db_pool", lambda: _Pool(store)) prefs = { f"aislo:pref:routeedit-view:{LIVE}": "a", f"aislo:pref:routeedit-view:{DEAD}": "b", "aislo:pref:table-open": "true", } asyncio.run(repo.save_user_ui_prefs(3, prefs)) assert store["saved"] == { f"aislo:pref:routeedit-view:{LIVE}": "a", "aislo:pref:table-open": "true", }