Add reauth to SFR Box (#86511)

This commit is contained in:
epenet 2023-01-24 11:00:22 +01:00 committed by GitHub
parent e084fe4903
commit 22dee1f92b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 144 additions and 9 deletions

View file

@ -3,7 +3,7 @@ from collections.abc import Generator
from unittest.mock import patch
import pytest
from sfrbox_api.exceptions import SFRBoxError
from sfrbox_api.exceptions import SFRBoxAuthenticationError, SFRBoxError
from homeassistant.components.sfr_box.const import DOMAIN
from homeassistant.config_entries import ConfigEntry, ConfigEntryState
@ -48,3 +48,35 @@ async def test_setup_entry_exception(
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
assert config_entry.state is ConfigEntryState.SETUP_RETRY
assert not hass.data.get(DOMAIN)
async def test_setup_entry_auth_exception(
hass: HomeAssistant, config_entry_with_auth: ConfigEntry
) -> None:
"""Test ConfigEntryNotReady when API raises an exception during authentication."""
with patch(
"homeassistant.components.sfr_box.coordinator.SFRBox.authenticate",
side_effect=SFRBoxError,
):
await hass.config_entries.async_setup(config_entry_with_auth.entry_id)
await hass.async_block_till_done()
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
assert config_entry_with_auth.state is ConfigEntryState.SETUP_RETRY
assert not hass.data.get(DOMAIN)
async def test_setup_entry_invalid_auth(
hass: HomeAssistant, config_entry_with_auth: ConfigEntry
) -> None:
"""Test ConfigEntryAuthFailed when API raises an exception during authentication."""
with patch(
"homeassistant.components.sfr_box.coordinator.SFRBox.authenticate",
side_effect=SFRBoxAuthenticationError,
):
await hass.config_entries.async_setup(config_entry_with_auth.entry_id)
await hass.async_block_till_done()
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
assert config_entry_with_auth.state is ConfigEntryState.SETUP_ERROR
assert not hass.data.get(DOMAIN)