coverage
This commit is contained in:
parent
2c1ba9dd63
commit
7588c888e2
|
@ -3,7 +3,7 @@
|
|||
from contextlib import contextmanager
|
||||
from unittest.mock import patch
|
||||
|
||||
from aiooncue import OncueDevice, OncueSensor
|
||||
from aiooncue import LoginFailedException, OncueDevice, OncueSensor
|
||||
|
||||
MOCK_ASYNC_FETCH_ALL = {
|
||||
"123456": OncueDevice(
|
||||
|
@ -861,3 +861,21 @@ def _patch_login_and_data_unavailable_device():
|
|||
yield
|
||||
|
||||
return _patcher()
|
||||
|
||||
|
||||
def _patch_login_and_data_auth_failure():
|
||||
@contextmanager
|
||||
def _patcher():
|
||||
with (
|
||||
patch(
|
||||
"homeassistant.components.oncue.Oncue.async_login",
|
||||
side_effect=LoginFailedException,
|
||||
),
|
||||
patch(
|
||||
"homeassistant.components.oncue.Oncue.async_fetch_all",
|
||||
side_effect=LoginFailedException,
|
||||
),
|
||||
):
|
||||
yield
|
||||
|
||||
return _patcher()
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import timedelta
|
||||
from unittest.mock import patch
|
||||
|
||||
from aiooncue import LoginFailedException
|
||||
|
@ -12,10 +13,11 @@ from homeassistant.config_entries import ConfigEntryState
|
|||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from . import _patch_login_and_data
|
||||
from . import _patch_login_and_data, _patch_login_and_data_auth_failure
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.common import MockConfigEntry, async_fire_time_changed
|
||||
|
||||
|
||||
async def test_config_entry_reload(hass: HomeAssistant) -> None:
|
||||
|
@ -67,3 +69,26 @@ async def test_config_entry_retry_later(hass: HomeAssistant) -> None:
|
|||
await async_setup_component(hass, oncue.DOMAIN, {oncue.DOMAIN: {}})
|
||||
await hass.async_block_till_done()
|
||||
assert config_entry.state is ConfigEntryState.SETUP_RETRY
|
||||
|
||||
|
||||
async def test_late_auth_failure(hass: HomeAssistant) -> None:
|
||||
"""Test auth fails after already setup."""
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data={CONF_USERNAME: "any", CONF_PASSWORD: "any"},
|
||||
unique_id="any",
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
with _patch_login_and_data():
|
||||
await async_setup_component(hass, oncue.DOMAIN, {oncue.DOMAIN: {}})
|
||||
await hass.async_block_till_done()
|
||||
assert config_entry.state is ConfigEntryState.LOADED
|
||||
|
||||
with _patch_login_and_data_auth_failure():
|
||||
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(minutes=10))
|
||||
await hass.async_block_till_done()
|
||||
|
||||
flows = hass.config_entries.flow.async_progress_by_handler(DOMAIN)
|
||||
assert len(flows) == 1
|
||||
flow = flows[0]
|
||||
assert flow["context"]["source"] == "reauth"
|
||||
|
|
Loading…
Reference in New Issue