Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that calendar output values are json types #95797

Merged
merged 1 commit into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion homeassistant/components/calendar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
8 changes: 8 additions & 0 deletions tests/components/calendar/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,11 @@
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")
17 changes: 12 additions & 5 deletions tests/components/calendar/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
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

Expand Down Expand Up @@ -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()

Expand All @@ -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",
Expand Down
8 changes: 0 additions & 8 deletions tests/components/calendar/test_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,6 @@ async def fire_until(self, end: datetime.datetime) -> None:
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
Expand Down