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."""
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
}

View file

@ -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")

View file

@ -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",

View file

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