mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 17:27:52 +00:00

* improve snoo testing * change to asyncMock method of testing * Apply suggestions from code review Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * address comments * Apply suggestions from code review Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * adress comments --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
33 lines
1.2 KiB
Python
33 lines
1.2 KiB
Python
"""Test init for Snoo."""
|
|
|
|
from unittest.mock import AsyncMock
|
|
|
|
from python_snoo.exceptions import SnooAuthException
|
|
|
|
from homeassistant.components.snoo import SnooDeviceError
|
|
from homeassistant.config_entries import ConfigEntryState
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from . import async_init_integration
|
|
|
|
|
|
async def test_async_setup_entry(hass: HomeAssistant, bypass_api: AsyncMock) -> None:
|
|
"""Test a successful setup entry."""
|
|
entry = await async_init_integration(hass)
|
|
assert len(hass.states.async_all("sensor")) == 2
|
|
assert entry.state == ConfigEntryState.LOADED
|
|
|
|
|
|
async def test_cannot_auth(hass: HomeAssistant, bypass_api: AsyncMock) -> None:
|
|
"""Test that we are put into retry when we fail to auth."""
|
|
bypass_api.authorize.side_effect = SnooAuthException
|
|
entry = await async_init_integration(hass)
|
|
assert entry.state is ConfigEntryState.SETUP_RETRY
|
|
|
|
|
|
async def test_failed_devices(hass: HomeAssistant, bypass_api: AsyncMock) -> None:
|
|
"""Test that we are put into retry when we fail to get devices."""
|
|
bypass_api.get_devices.side_effect = SnooDeviceError
|
|
entry = await async_init_integration(hass)
|
|
assert entry.state is ConfigEntryState.SETUP_RETRY
|