Ensure that calendar output values are json types (#95797)

This commit is contained in:
Allen Porter 2023-07-03 12:05:02 -07:00 committed by GitHub
parent 0f725a24bd
commit 2f73be0e50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 14 deletions

View File

@ -422,7 +422,7 @@ def _list_events_dict_factory(
"""Convert CalendarEvent dataclass items to dictionary of attributes.""" """Convert CalendarEvent dataclass items to dictionary of attributes."""
return { return {
name: value 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 if name in LIST_EVENT_FIELDS and value is not None
} }

View File

@ -9,3 +9,11 @@ from homeassistant.setup import async_setup_component
async def setup_homeassistant(hass: HomeAssistant): async def setup_homeassistant(hass: HomeAssistant):
"""Set up the homeassistant integration.""" """Set up the homeassistant integration."""
await async_setup_component(hass, "homeassistant", {}) 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")

View File

@ -4,8 +4,9 @@ from __future__ import annotations
from datetime import timedelta from datetime import timedelta
from http import HTTPStatus from http import HTTPStatus
from typing import Any from typing import Any
from unittest.mock import ANY, patch from unittest.mock import patch
from freezegun import freeze_time
import pytest import pytest
import voluptuous as vol 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: @freeze_time("2023-06-22 10:30:00+00:00")
"""Test listing events from the service call using exlplicit start and end time.""" 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 async_setup_component(hass, "calendar", {"calendar": {"platform": "demo"}})
await hass.async_block_till_done() await hass.async_block_till_done()
@ -408,8 +415,8 @@ async def test_list_events_service(hass: HomeAssistant) -> None:
assert response == { assert response == {
"events": [ "events": [
{ {
"start": ANY, "start": "2023-06-22T05:00:00-06:00",
"end": ANY, "end": "2023-06-22T06:00:00-06:00",
"summary": "Future Event", "summary": "Future Event",
"description": "Future Description", "description": "Future Description",
"location": "Future Location", "location": "Future Location",

View File

@ -121,14 +121,6 @@ class FakeSchedule:
await self.fire_time(dt_util.utcnow()) 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 @pytest.fixture
def fake_schedule( def fake_schedule(
hass: HomeAssistant, freezer: FrozenDateTimeFactory hass: HomeAssistant, freezer: FrozenDateTimeFactory