Ensure that calendar output values are json types (#95797)
This commit is contained in:
parent
0f725a24bd
commit
2f73be0e50
4 changed files with 21 additions and 14 deletions
|
@ -422,7 +422,7 @@ def _list_events_dict_factory(
|
|||
"""Convert CalendarEvent dataclass items to dictionary of attributes."""
|
||||
return {
|
||||
name: value
|
||||
for name, value in obj
|
||||
for name, value in _event_dict_factory(obj).items()
|
||||
if name in LIST_EVENT_FIELDS and value is not None
|
||||
}
|
||||
|
||||
|
|
|
@ -9,3 +9,11 @@ from homeassistant.setup import async_setup_component
|
|||
async def setup_homeassistant(hass: HomeAssistant):
|
||||
"""Set up the homeassistant integration."""
|
||||
await async_setup_component(hass, "homeassistant", {})
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def set_time_zone(hass: HomeAssistant) -> None:
|
||||
"""Set the time zone for the tests."""
|
||||
# Set our timezone to CST/Regina so we can check calculations
|
||||
# This keeps UTC-6 all year round
|
||||
hass.config.set_time_zone("America/Regina")
|
||||
|
|
|
@ -4,8 +4,9 @@ from __future__ import annotations
|
|||
from datetime import timedelta
|
||||
from http import HTTPStatus
|
||||
from typing import Any
|
||||
from unittest.mock import ANY, patch
|
||||
from unittest.mock import patch
|
||||
|
||||
from freezegun import freeze_time
|
||||
import pytest
|
||||
import voluptuous as vol
|
||||
|
||||
|
@ -386,8 +387,14 @@ async def test_create_event_service_invalid_params(
|
|||
)
|
||||
|
||||
|
||||
async def test_list_events_service(hass: HomeAssistant) -> None:
|
||||
"""Test listing events from the service call using exlplicit start and end time."""
|
||||
@freeze_time("2023-06-22 10:30:00+00:00")
|
||||
async def test_list_events_service(hass: HomeAssistant, set_time_zone: None) -> None:
|
||||
"""Test listing events from the service call using exlplicit start and end time.
|
||||
|
||||
This test uses a fixed date/time so that it can deterministically test the
|
||||
string output values.
|
||||
"""
|
||||
|
||||
await async_setup_component(hass, "calendar", {"calendar": {"platform": "demo"}})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
@ -408,8 +415,8 @@ async def test_list_events_service(hass: HomeAssistant) -> None:
|
|||
assert response == {
|
||||
"events": [
|
||||
{
|
||||
"start": ANY,
|
||||
"end": ANY,
|
||||
"start": "2023-06-22T05:00:00-06:00",
|
||||
"end": "2023-06-22T06:00:00-06:00",
|
||||
"summary": "Future Event",
|
||||
"description": "Future Description",
|
||||
"location": "Future Location",
|
||||
|
|
|
@ -121,14 +121,6 @@ class FakeSchedule:
|
|||
await self.fire_time(dt_util.utcnow())
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def set_time_zone(hass: HomeAssistant) -> None:
|
||||
"""Set the time zone for the tests."""
|
||||
# Set our timezone to CST/Regina so we can check calculations
|
||||
# This keeps UTC-6 all year round
|
||||
hass.config.set_time_zone("America/Regina")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def fake_schedule(
|
||||
hass: HomeAssistant, freezer: FrozenDateTimeFactory
|
||||
|
|
Loading…
Add table
Reference in a new issue