|
1 | 1 | """Tests for calendar platform of Remote Calendar."""
|
2 | 2 |
|
3 | 3 | from datetime import datetime
|
| 4 | +import pathlib |
4 | 5 | import textwrap
|
5 | 6 |
|
6 | 7 | from httpx import Response
|
7 | 8 | import pytest
|
8 | 9 | import respx
|
| 10 | +from syrupy.assertion import SnapshotAssertion |
9 | 11 |
|
10 | 12 | from homeassistant.const import STATE_OFF, STATE_ON
|
11 | 13 | from homeassistant.core import HomeAssistant
|
|
21 | 23 |
|
22 | 24 | from tests.common import MockConfigEntry
|
23 | 25 |
|
| 26 | +# Test data files with known calendars from various sources. You can add a new file |
| 27 | +# in the testdata directory and add it will be parsed and tested. |
| 28 | +TESTDATA_FILES = sorted( |
| 29 | + pathlib.Path("tests/components/remote_calendar/testdata/").glob("*.ics") |
| 30 | +) |
| 31 | +TESTDATA_IDS = [f.stem for f in TESTDATA_FILES] |
| 32 | + |
24 | 33 |
|
25 | 34 | @respx.mock
|
26 | 35 | async def test_empty_calendar(
|
@@ -392,3 +401,24 @@ async def test_all_day_iter_order(
|
392 | 401 |
|
393 | 402 | events = await get_events("2022-10-06T00:00:00Z", "2022-10-09T00:00:00Z")
|
394 | 403 | assert [event["summary"] for event in events] == event_order
|
| 404 | + |
| 405 | + |
| 406 | +@respx.mock |
| 407 | +@pytest.mark.parametrize("ics_filename", TESTDATA_FILES, ids=TESTDATA_IDS) |
| 408 | +async def test_calendar_examples( |
| 409 | + hass: HomeAssistant, |
| 410 | + config_entry: MockConfigEntry, |
| 411 | + get_events: GetEventsFn, |
| 412 | + ics_filename: pathlib.Path, |
| 413 | + snapshot: SnapshotAssertion, |
| 414 | +) -> None: |
| 415 | + """Test parsing known calendars form test data files.""" |
| 416 | + respx.get(CALENDER_URL).mock( |
| 417 | + return_value=Response( |
| 418 | + status_code=200, |
| 419 | + text=ics_filename.read_text(), |
| 420 | + ) |
| 421 | + ) |
| 422 | + await setup_integration(hass, config_entry) |
| 423 | + events = await get_events("1997-07-14T00:00:00", "2025-07-01T00:00:00") |
| 424 | + assert events == snapshot |
0 commit comments