"""Tests for the Airbnb reservation-detail TTL cache (TTLCache in _month_cache.py). Month-cache mechanics (TTL, in-flight dedup, suspect retry, on_evict wiring) are covered generically across both clients in test_service_client_conformance.py; TTLCache mechanics in general are covered in test_month_cache.py. This file is what's left that's Airbnb-specific: the per-reservation detail cache (self._details) has no analog on Booking.com. """ import time from room_cal.service_api._utils import CACHE_TTL _EXPIRED = -(CACHE_TTL + 1) def _airbnb_client(): from room_cal.service_api._airbnb import _AirbnbClient return _AirbnbClient(cookies='test', listing_id='12345678') class TestAirbnbDetailTTL: def _stub_gql(self, client, det): async def _gql(op, h, variables, referer): return {'data': {'presentation': {'hostingDetails': {'stayHostingDetails': det}}}} client._gql = _gql async def test_fresh_detail_served_from_cache(self): client = _airbnb_client() client._details.set('C1', {'cached': True}) self._stub_gql(client, {'fresh': True}) assert await client._fetch_one_detail('C1') == {'cached': True} async def test_expired_detail_refetches(self): client = _airbnb_client() client._details._data['C1'] = {'cached': True} client._details._fetched_at['C1'] = time.monotonic() + _EXPIRED self._stub_gql(client, {'fresh': True}) assert await client._fetch_one_detail('C1') == {'fresh': True} assert client._details.get('C1') == {'fresh': True}