* Initial commit for Dexcom integration * Dexcom config flow testing * Clarify errors during setup * Resolve minor test issues * Update sensor availability, resolve linting issues * Add sensor tests * Remove title due to 0.109, add abort * >94.97% codecov/patch * Move .translations/ to translations/ * Add constants for servers and unit of measurements * Bump pydexcom version * Updated domain schema, Dexcom creation * Support for different units of measurement * Update tests * Remove empty items from manifest Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Raise UpdateFailed if fetching new session fails * Switch everything over to required * Simplify state information * Simplify async_on_remove * Pydexcom package now handles fetching new session * Only allow config flow * Remove ternary operator * Bump version, pydexcom handling session refresh * Using common strings * Import from test.async_mock * Shorten variable names * Resolve tests after removing yaml support * Return false if credentials are invalid * Available seems to handle if data is empty * Now using option flow, remove handling import * Add fixture for JSON returned from API * Overhaul testing * Revise update options * Bump pydexcom version * Combat listener repetition * Undo update listener using callback * Change sensor availability to use last_update_success * Update sensor availability and tests * Rename test Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
61 lines
1.8 KiB
Python
61 lines
1.8 KiB
Python
"""Test the Dexcom config flow."""
|
|
from pydexcom import AccountError, SessionError
|
|
|
|
from homeassistant.components.dexcom.const import DOMAIN
|
|
from homeassistant.config_entries import ENTRY_STATE_LOADED, ENTRY_STATE_NOT_LOADED
|
|
|
|
from tests.async_mock import patch
|
|
from tests.common import MockConfigEntry
|
|
from tests.components.dexcom import CONFIG, init_integration
|
|
|
|
|
|
async def test_setup_entry_account_error(hass):
|
|
"""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(
|
|
"homeassistant.components.dexcom.Dexcom", side_effect=AccountError,
|
|
):
|
|
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):
|
|
"""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(
|
|
"homeassistant.components.dexcom.Dexcom", side_effect=SessionError,
|
|
):
|
|
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):
|
|
"""Test successful unload of entry."""
|
|
entry = await init_integration(hass)
|
|
|
|
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
|
assert entry.state == ENTRY_STATE_LOADED
|
|
|
|
assert await hass.config_entries.async_unload(entry.entry_id)
|
|
await hass.async_block_till_done()
|
|
|
|
assert entry.state == ENTRY_STATE_NOT_LOADED
|
|
assert not hass.data.get(DOMAIN)
|