mirror of
https://github.com/home-assistant/core.git
synced 2025-11-14 13:30:43 +00:00
Add a Local To-do component (#102627)
Co-authored-by: Robert Resch <robert@resch.dev> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
60
tests/components/local_todo/test_init.py
Normal file
60
tests/components/local_todo/test_init.py
Normal file
@@ -0,0 +1,60 @@
|
||||
"""Tests for init platform of local_todo."""
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .conftest import TEST_ENTITY
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_load_unload(
|
||||
hass: HomeAssistant, setup_integration: None, config_entry: MockConfigEntry
|
||||
) -> None:
|
||||
"""Test loading and unloading a config entry."""
|
||||
|
||||
assert config_entry.state == ConfigEntryState.LOADED
|
||||
|
||||
state = hass.states.get(TEST_ENTITY)
|
||||
assert state
|
||||
assert state.state == "0"
|
||||
|
||||
await hass.config_entries.async_unload(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert config_entry.state == ConfigEntryState.NOT_LOADED
|
||||
state = hass.states.get(TEST_ENTITY)
|
||||
assert state
|
||||
assert state.state == "unavailable"
|
||||
|
||||
|
||||
async def test_remove_config_entry(
|
||||
hass: HomeAssistant, setup_integration: None, config_entry: MockConfigEntry
|
||||
) -> None:
|
||||
"""Test removing a config entry."""
|
||||
|
||||
with patch("homeassistant.components.local_todo.Path.unlink") as unlink_mock:
|
||||
assert await hass.config_entries.async_remove(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
unlink_mock.assert_called_once()
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("store_read_side_effect"),
|
||||
[
|
||||
(OSError("read error")),
|
||||
],
|
||||
)
|
||||
async def test_load_failure(
|
||||
hass: HomeAssistant, setup_integration: None, config_entry: MockConfigEntry
|
||||
) -> None:
|
||||
"""Test failures loading the todo store."""
|
||||
|
||||
assert config_entry.state == ConfigEntryState.SETUP_RETRY
|
||||
|
||||
state = hass.states.get(TEST_ENTITY)
|
||||
assert not state
|
||||
Reference in New Issue
Block a user