mirror of
https://github.com/home-assistant/core.git
synced 2025-11-13 04:50:17 +00:00
72 lines
2.1 KiB
Python
72 lines
2.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.components.portainer.const import DOMAIN
|
|
from homeassistant.config_entries import ConfigEntryState
|
|
from homeassistant.const import (
|
|
CONF_API_KEY,
|
|
CONF_API_TOKEN,
|
|
CONF_HOST,
|
|
CONF_URL,
|
|
CONF_VERIFY_SSL,
|
|
)
|
|
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
|
|
|
|
|
|
async def test_migrations(hass: HomeAssistant) -> None:
|
|
"""Test migration from v1 config entry."""
|
|
entry = MockConfigEntry(
|
|
domain=DOMAIN,
|
|
data={
|
|
CONF_HOST: "http://test_host",
|
|
CONF_API_KEY: "test_key",
|
|
},
|
|
unique_id="1",
|
|
version=1,
|
|
)
|
|
entry.add_to_hass(hass)
|
|
assert entry.version == 1
|
|
assert CONF_VERIFY_SSL not in entry.data
|
|
await hass.config_entries.async_setup(entry.entry_id)
|
|
await hass.async_block_till_done()
|
|
|
|
assert entry.version == 3
|
|
assert CONF_HOST not in entry.data
|
|
assert CONF_API_KEY not in entry.data
|
|
assert entry.data[CONF_URL] == "http://test_host"
|
|
assert entry.data[CONF_API_TOKEN] == "test_key"
|
|
assert entry.data[CONF_VERIFY_SSL] is True
|