From d7e195ba40b47821d294cbbcf7b0f00e73065f3b Mon Sep 17 00:00:00 2001 From: Kevin Stillhammer Date: Fri, 20 Oct 2023 15:14:31 +0200 Subject: [PATCH] Use snapshots in calendar tests (#102299) --- .../calendar/snapshots/test_init.ambr | 31 +++++++++++++++++++ tests/components/calendar/test_init.py | 24 +++++++------- 2 files changed, 44 insertions(+), 11 deletions(-) create mode 100644 tests/components/calendar/snapshots/test_init.ambr diff --git a/tests/components/calendar/snapshots/test_init.ambr b/tests/components/calendar/snapshots/test_init.ambr new file mode 100644 index 00000000000..7d48228193a --- /dev/null +++ b/tests/components/calendar/snapshots/test_init.ambr @@ -0,0 +1,31 @@ +# serializer version: 1 +# name: test_list_events_service_duration[calendar.calendar_1-00:15:00] + dict({ + 'events': list([ + ]), + }) +# --- +# name: test_list_events_service_duration[calendar.calendar_1-01:00:00] + dict({ + 'events': list([ + dict({ + 'description': 'Future Description', + 'end': '2023-10-19T08:20:05-07:00', + 'location': 'Future Location', + 'start': '2023-10-19T07:20:05-07:00', + 'summary': 'Future Event', + }), + ]), + }) +# --- +# name: test_list_events_service_duration[calendar.calendar_2-00:15:00] + dict({ + 'events': list([ + dict({ + 'end': '2023-10-19T07:20:05-07:00', + 'start': '2023-10-19T06:20:05-07:00', + 'summary': 'Current Event', + }), + ]), + }) +# --- diff --git a/tests/components/calendar/test_init.py b/tests/components/calendar/test_init.py index e0fbbf0cdeb..ad83d039d73 100644 --- a/tests/components/calendar/test_init.py +++ b/tests/components/calendar/test_init.py @@ -8,6 +8,7 @@ from unittest.mock import patch from freezegun import freeze_time import pytest +from syrupy.assertion import SnapshotAssertion import voluptuous as vol from homeassistant.bootstrap import async_setup_component @@ -368,7 +369,7 @@ async def test_create_event_service_invalid_params( date_fields: dict[str, Any], expected_error: type[Exception], error_match: str | None, -): +) -> None: """Test creating an event using the create_event service.""" await async_setup_component(hass, "calendar", {"calendar": {"platform": "demo"}}) @@ -397,7 +398,10 @@ async def test_create_event_service_invalid_params( ], ) async def test_list_events_service( - hass: HomeAssistant, set_time_zone: None, start_time: str, end_time: str + hass: HomeAssistant, + set_time_zone: None, + start_time: str, + end_time: str, ) -> None: """Test listing events from the service call using exlplicit start and end time. @@ -433,21 +437,22 @@ async def test_list_events_service( @pytest.mark.parametrize( - ("entity", "duration", "expected_events"), + ("entity", "duration"), [ # Calendar 1 has an hour long event starting in 30 minutes. No events in the # next 15 minutes, but it shows up an hour from now. - ("calendar.calendar_1", "00:15:00", []), - ("calendar.calendar_1", "01:00:00", ["Future Event"]), + ("calendar.calendar_1", "00:15:00"), + ("calendar.calendar_1", "01:00:00"), # Calendar 2 has a active event right now - ("calendar.calendar_2", "00:15:00", ["Current Event"]), + ("calendar.calendar_2", "00:15:00"), ], ) +@pytest.mark.freeze_time("2023-10-19 13:50:05") async def test_list_events_service_duration( hass: HomeAssistant, entity: str, duration: str, - expected_events: list[str], + snapshot: SnapshotAssertion, ) -> None: """Test listing events using a time duration.""" await async_setup_component(hass, "calendar", {"calendar": {"platform": "demo"}}) @@ -463,10 +468,7 @@ async def test_list_events_service_duration( blocking=True, return_response=True, ) - assert response - assert "events" in response - events = response["events"] - assert [event["summary"] for event in events] == expected_events + assert response == snapshot async def test_list_events_positive_duration(hass: HomeAssistant) -> None: