mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 10:47:10 +00:00
Use snapshots in calendar tests (#102299)
This commit is contained in:
parent
8202071683
commit
d7e195ba40
31
tests/components/calendar/snapshots/test_init.ambr
Normal file
31
tests/components/calendar/snapshots/test_init.ambr
Normal 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',
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
})
|
||||||
|
# ---
|
@ -8,6 +8,7 @@ from unittest.mock import patch
|
|||||||
|
|
||||||
from freezegun import freeze_time
|
from freezegun import freeze_time
|
||||||
import pytest
|
import pytest
|
||||||
|
from syrupy.assertion import SnapshotAssertion
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.bootstrap import async_setup_component
|
from homeassistant.bootstrap import async_setup_component
|
||||||
@ -368,7 +369,7 @@ async def test_create_event_service_invalid_params(
|
|||||||
date_fields: dict[str, Any],
|
date_fields: dict[str, Any],
|
||||||
expected_error: type[Exception],
|
expected_error: type[Exception],
|
||||||
error_match: str | None,
|
error_match: str | None,
|
||||||
):
|
) -> None:
|
||||||
"""Test creating an event using the create_event service."""
|
"""Test creating an event using the create_event service."""
|
||||||
|
|
||||||
await async_setup_component(hass, "calendar", {"calendar": {"platform": "demo"}})
|
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(
|
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:
|
) -> None:
|
||||||
"""Test listing events from the service call using exlplicit start and end time.
|
"""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(
|
@pytest.mark.parametrize(
|
||||||
("entity", "duration", "expected_events"),
|
("entity", "duration"),
|
||||||
[
|
[
|
||||||
# Calendar 1 has an hour long event starting in 30 minutes. No events in the
|
# 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.
|
# next 15 minutes, but it shows up an hour from now.
|
||||||
("calendar.calendar_1", "00:15:00", []),
|
("calendar.calendar_1", "00:15:00"),
|
||||||
("calendar.calendar_1", "01:00:00", ["Future Event"]),
|
("calendar.calendar_1", "01:00:00"),
|
||||||
# Calendar 2 has a active event right now
|
# 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(
|
async def test_list_events_service_duration(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entity: str,
|
entity: str,
|
||||||
duration: str,
|
duration: str,
|
||||||
expected_events: list[str],
|
snapshot: SnapshotAssertion,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test listing events using a time duration."""
|
"""Test listing events using a time duration."""
|
||||||
await async_setup_component(hass, "calendar", {"calendar": {"platform": "demo"}})
|
await async_setup_component(hass, "calendar", {"calendar": {"platform": "demo"}})
|
||||||
@ -463,10 +468,7 @@ async def test_list_events_service_duration(
|
|||||||
blocking=True,
|
blocking=True,
|
||||||
return_response=True,
|
return_response=True,
|
||||||
)
|
)
|
||||||
assert response
|
assert response == snapshot
|
||||||
assert "events" in response
|
|
||||||
events = response["events"]
|
|
||||||
assert [event["summary"] for event in events] == expected_events
|
|
||||||
|
|
||||||
|
|
||||||
async def test_list_events_positive_duration(hass: HomeAssistant) -> None:
|
async def test_list_events_positive_duration(hass: HomeAssistant) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user