core/tests/components/dexcom/test_init.py

67 lines
1.9 KiB
Python
Raw Normal View History

2020-07-02 00:14:54 +00:00
"""Test the Dexcom config flow."""
2021-01-01 21:31:56 +00:00
from unittest.mock import patch
2020-07-02 00:14:54 +00:00
from pydexcom import AccountError, SessionError
from homeassistant.components.dexcom.const import DOMAIN
from homeassistant.config_entries import ConfigEntryState
from homeassistant.core import HomeAssistant
2020-07-02 00:14:54 +00:00
from . import CONFIG, init_integration
2020-07-02 00:14:54 +00:00
from tests.common import MockConfigEntry
async def test_setup_entry_account_error(hass: HomeAssistant) -> None:
2020-07-02 00:14:54 +00:00
"""Test entry setup failed due to account error."""
entry = MockConfigEntry(
domain=DOMAIN,
title="test_username",
unique_id="test_username",
data=CONFIG,
options=None,
)
with patch(
2020-08-27 11:56:20 +00:00
"homeassistant.components.dexcom.Dexcom",
side_effect=AccountError,
2020-07-02 00:14:54 +00:00
):
entry.add_to_hass(hass)
result = await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
assert result is False
async def test_setup_entry_session_error(hass: HomeAssistant) -> None:
2020-07-02 00:14:54 +00:00
"""Test entry setup failed due to session error."""
entry = MockConfigEntry(
domain=DOMAIN,
title="test_username",
unique_id="test_username",
data=CONFIG,
options=None,
)
with patch(
2020-08-27 11:56:20 +00:00
"homeassistant.components.dexcom.Dexcom",
side_effect=SessionError,
2020-07-02 00:14:54 +00:00
):
entry.add_to_hass(hass)
result = await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
assert result is False
async def test_unload_entry(hass: HomeAssistant) -> None:
2020-07-02 00:14:54 +00:00
"""Test successful unload of entry."""
entry = await init_integration(hass)
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
assert entry.state is ConfigEntryState.LOADED
2020-07-02 00:14:54 +00:00
assert await hass.config_entries.async_unload(entry.entry_id)
await hass.async_block_till_done()
assert entry.state is ConfigEntryState.NOT_LOADED
2020-07-02 00:14:54 +00:00
assert not hass.data.get(DOMAIN)