Introduce reauthentication flow to UniFi integration (#45360)
* Improve site selection * Reauth flow and tests Add **kwargs to mock_aiohttp_client create_session to support inputting verify_ssl and cookie_jar * Update homeassistant/components/unifi/config_flow.py Co-authored-by: J. Nick Koston <nick@koston.org> * Minor improvements * Improve coverage Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
parent
7ff02fe8d4
commit
da4404e8cf
7 changed files with 157 additions and 38 deletions
|
@ -222,6 +222,17 @@ async def test_controller_not_accessible(hass):
|
|||
assert hass.data[UNIFI_DOMAIN] == {}
|
||||
|
||||
|
||||
async def test_controller_trigger_reauth_flow(hass):
|
||||
"""Failed authentication trigger a reauthentication flow."""
|
||||
with patch(
|
||||
"homeassistant.components.unifi.controller.get_controller",
|
||||
side_effect=AuthenticationRequired,
|
||||
), patch.object(hass.config_entries.flow, "async_init") as mock_flow_init:
|
||||
await setup_unifi_integration(hass)
|
||||
mock_flow_init.assert_called_once()
|
||||
assert hass.data[UNIFI_DOMAIN] == {}
|
||||
|
||||
|
||||
async def test_controller_unknown_error(hass):
|
||||
"""Unknown errors are handled."""
|
||||
with patch(
|
||||
|
@ -319,6 +330,14 @@ async def test_get_controller_controller_unavailable(hass):
|
|||
await get_controller(hass, **CONTROLLER_DATA)
|
||||
|
||||
|
||||
async def test_get_controller_login_required(hass):
|
||||
"""Check that get_controller can handle unknown errors."""
|
||||
with patch("aiounifi.Controller.check_unifi_os", return_value=True), patch(
|
||||
"aiounifi.Controller.login", side_effect=aiounifi.LoginRequired
|
||||
), pytest.raises(AuthenticationRequired):
|
||||
await get_controller(hass, **CONTROLLER_DATA)
|
||||
|
||||
|
||||
async def test_get_controller_unknown_error(hass):
|
||||
"""Check that get_controller can handle unknown errors."""
|
||||
with patch("aiounifi.Controller.check_unifi_os", return_value=True), patch(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue