mirror of
https://github.com/home-assistant/core.git
synced 2025-12-20 02:48:57 +00:00
Co-authored-by: Manu <4445816+tr4nt0r@users.noreply.github.com> Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
"""Test the Portainer initial specific behavior."""
|
|
|
|
from unittest.mock import AsyncMock
|
|
|
|
from pyportainer.exceptions import (
|
|
PortainerAuthenticationError,
|
|
PortainerConnectionError,
|
|
PortainerTimeoutError,
|
|
)
|
|
import pytest
|
|
|
|
from homeassistant.config_entries import ConfigEntryState
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from . import setup_integration
|
|
|
|
from tests.common import MockConfigEntry
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("exception", "expected_state"),
|
|
[
|
|
(PortainerAuthenticationError("bad creds"), ConfigEntryState.SETUP_ERROR),
|
|
(PortainerConnectionError("cannot connect"), ConfigEntryState.SETUP_RETRY),
|
|
(PortainerTimeoutError("timeout"), ConfigEntryState.SETUP_RETRY),
|
|
],
|
|
)
|
|
async def test_setup_exceptions(
|
|
hass: HomeAssistant,
|
|
mock_portainer_client: AsyncMock,
|
|
mock_config_entry: MockConfigEntry,
|
|
exception: Exception,
|
|
expected_state: ConfigEntryState,
|
|
) -> None:
|
|
"""Test the _async_setup."""
|
|
mock_portainer_client.get_endpoints.side_effect = exception
|
|
await setup_integration(hass, mock_config_entry)
|
|
assert mock_config_entry.state == expected_state
|