"""네거티브 캐시 CRUD 테스트 (실 lps_db).""" import pytest_asyncio from sqlalchemy import text from crud.negative_cache import NegativeCache @pytest_asyncio.fixture async def nc(db_engine): async with db_engine.begin() as conn: await conn.execute(text("TRUNCATE search_negative")) return NegativeCache() async def test_put_then_is_negative(nc): assert await nc.is_negative("P1") is False await nc.put("P1", ttl_sec=3600) assert await nc.is_negative("P1") is True async def test_expired_is_not_negative(nc): await nc.put("P2", ttl_sec=-1) # 이미 만료 assert await nc.is_negative("P2") is False async def test_upsert_refreshes_ttl(nc): await nc.put("P3", ttl_sec=-1) # 만료 상태 assert await nc.is_negative("P3") is False await nc.put("P3", ttl_sec=3600) # 갱신 → 유효 assert await nc.is_negative("P3") is True async def test_empty_key_is_noop(nc): await nc.put("", ttl_sec=3600) assert await nc.is_negative("") is False