hass-core/tests/components/habitica/test_calendar.py
Manu 6887a4419e
Add calendar platform to Habitica integration (#128248)
* Add calendar platform

* Add tests

* add missing reminders filter by date

* Add +1 day to todo end

* add 1 day to dailies, remove unused line of code

* Removing reminders calendar to a separate PR

* fix upcoming event for dailies

* util function for rrule string

* Add test for get_recurrence_rule

* use habitica daystart and account for isDue flag

* yesterdaily is still an active event

* Fix yesterdailies and add attribute

* Update snapshot

* Use iter, return attribute with None value

* various changes

* update snapshot

* fix merge error

* update snapshot

* change date range filtering for todos

* use datetimes instead of date in async_get_events

* Sort events

* Update snapshot

* add method for todos

* filter for upcoming events

* dailies

* refactor todos

* update dailies logic

* dedent loops
2024-10-29 20:53:49 -07:00

80 lines
2.2 KiB
Python

"""Tests for the Habitica calendar platform."""
from collections.abc import Generator
from unittest.mock import patch
import pytest
from syrupy.assertion import SnapshotAssertion
from homeassistant.config_entries import ConfigEntryState
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from tests.common import MockConfigEntry, snapshot_platform
from tests.typing import ClientSessionGenerator
@pytest.fixture(autouse=True)
def calendar_only() -> Generator[None]:
"""Enable only the calendar platform."""
with patch(
"homeassistant.components.habitica.PLATFORMS",
[Platform.CALENDAR],
):
yield
@pytest.fixture(autouse=True)
async def set_tz(hass: HomeAssistant) -> None:
"""Fixture to set timezone."""
await hass.config.async_set_time_zone("Europe/Berlin")
@pytest.mark.usefixtures("mock_habitica")
@pytest.mark.freeze_time("2024-09-20T22:00:00.000Z")
async def test_calendar_platform(
hass: HomeAssistant,
config_entry: MockConfigEntry,
snapshot: SnapshotAssertion,
entity_registry: er.EntityRegistry,
) -> None:
"""Test setup of the Habitica calendar platform."""
config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
assert config_entry.state is ConfigEntryState.LOADED
await snapshot_platform(hass, entity_registry, snapshot, config_entry.entry_id)
@pytest.mark.parametrize(
("entity"),
[
"calendar.test_user_to_do_s",
"calendar.test_user_dailies",
],
)
@pytest.mark.freeze_time("2024-09-20T22:00:00.000Z")
@pytest.mark.usefixtures("mock_habitica")
async def test_api_events(
hass: HomeAssistant,
snapshot: SnapshotAssertion,
config_entry: MockConfigEntry,
hass_client: ClientSessionGenerator,
entity: str,
) -> None:
"""Test calendar event."""
config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
client = await hass_client()
response = await client.get(
f"/api/calendars/{entity}?start=2024-08-29&end=2024-10-08"
)
assert await response.json() == snapshot