Proper handling of authentication errors in AVM Fritz!Tools (#79434)

This commit is contained in:
Michael 2023-02-01 16:03:18 +01:00 committed by GitHub
parent afa55156d6
commit 2f51059b7f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 57 additions and 21 deletions

View file

@ -1,14 +1,17 @@
"""Tests for Fritz!Tools."""
from unittest.mock import patch
from fritzconnection.core.exceptions import FritzSecurityError
import pytest
from homeassistant.components.device_tracker import (
CONF_CONSIDER_HOME,
DEFAULT_CONSIDER_HOME,
)
from homeassistant.components.fritz.const import DOMAIN, FRITZ_EXCEPTIONS
from homeassistant.components.fritz.const import (
DOMAIN,
FRITZ_AUTH_EXCEPTIONS,
FRITZ_EXCEPTIONS,
)
from homeassistant.config_entries import ConfigEntryState
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component
@ -60,7 +63,11 @@ async def test_options_reload(hass: HomeAssistant, fc_class_mock, fh_class_mock)
mock_reload.assert_called_once()
async def test_setup_auth_fail(hass: HomeAssistant):
@pytest.mark.parametrize(
"error",
FRITZ_AUTH_EXCEPTIONS,
)
async def test_setup_auth_fail(hass: HomeAssistant, error):
"""Test starting a flow by user with an already configured device."""
entry = MockConfigEntry(domain=DOMAIN, data=MOCK_USER_DATA)
@ -68,7 +75,7 @@ async def test_setup_auth_fail(hass: HomeAssistant):
with patch(
"homeassistant.components.fritz.common.FritzConnection",
side_effect=FritzSecurityError,
side_effect=error,
):
assert await async_setup_component(hass, DOMAIN, {})
await hass.async_block_till_done()