import pytest from room_cal._utils import CalendarEntry from room_cal.ical_feeds import fetch_calendar _REQUIRED_KEYS = {'calendar', 'start', 'end', 'all_day', 'title', 'description', 'uid'} _FIRE_ENTRY = CalendarEntry(name='Fire', url='webcal://cal.4114.us/fire.ics') _HOUSE_ENTRY = CalendarEntry(name='House', caldav='House') def _assert_events(events: list, expected_calendar: str): assert isinstance(events, list), "fetch_calendar should return a list" for e in events: missing = _REQUIRED_KEYS - e.keys() assert not missing, f"Event missing keys: {missing}" assert e['calendar'] == expected_calendar assert e['end'] >= e['start'] @pytest.mark.asyncio async def test_fire_http_ical(): events = await fetch_calendar(_FIRE_ENTRY) _assert_events(events, 'Fire') @pytest.mark.asyncio async def test_house_caldav(): events = await fetch_calendar(_HOUSE_ENTRY) _assert_events(events, 'House')