Use snapshots in calendar tests (#102299)

This commit is contained in:
Kevin Stillhammer 2023-10-20 15:14:31 +02:00 committed by GitHub
parent 8202071683
commit d7e195ba40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 11 deletions

View File

@ -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',
}),
]),
})
# ---

View File

@ -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: