Add re-auth flow to glances integration (#100929)
* Add reauth flow to glances integration. * add reauth string * add reauth strings
This commit is contained in:
parent
c823e407fd
commit
785b46af22
5 changed files with 155 additions and 7 deletions
|
@ -1,7 +1,11 @@
|
|||
"""Tests for Glances integration."""
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from glances_api.exceptions import GlancesApiConnectionError
|
||||
from glances_api.exceptions import (
|
||||
GlancesApiAuthorizationError,
|
||||
GlancesApiConnectionError,
|
||||
)
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.glances.const import DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
|
@ -23,15 +27,27 @@ async def test_successful_config_entry(hass: HomeAssistant) -> None:
|
|||
assert entry.state == ConfigEntryState.LOADED
|
||||
|
||||
|
||||
async def test_conn_error(hass: HomeAssistant, mock_api: MagicMock) -> None:
|
||||
"""Test Glances failed due to connection error."""
|
||||
@pytest.mark.parametrize(
|
||||
("error", "entry_state"),
|
||||
[
|
||||
(GlancesApiAuthorizationError, ConfigEntryState.SETUP_ERROR),
|
||||
(GlancesApiConnectionError, ConfigEntryState.SETUP_RETRY),
|
||||
],
|
||||
)
|
||||
async def test_setup_error(
|
||||
hass: HomeAssistant,
|
||||
error: Exception,
|
||||
entry_state: ConfigEntryState,
|
||||
mock_api: MagicMock,
|
||||
) -> None:
|
||||
"""Test Glances failed due to api error."""
|
||||
|
||||
entry = MockConfigEntry(domain=DOMAIN, data=MOCK_USER_INPUT)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
mock_api.return_value.get_ha_sensor_data.side_effect = GlancesApiConnectionError
|
||||
mock_api.return_value.get_ha_sensor_data.side_effect = error
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
assert entry.state is ConfigEntryState.SETUP_RETRY
|
||||
assert entry.state is entry_state
|
||||
|
||||
|
||||
async def test_unload_entry(hass: HomeAssistant) -> None:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue