mirror of
https://github.com/home-assistant/core.git
synced 2026-05-20 07:20:14 +01:00
ec918e0460
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Joostlek <joostlek@outlook.com>
48 lines
1.3 KiB
Python
48 lines
1.3 KiB
Python
"""Test the Guntamatic integration setup."""
|
|
|
|
from unittest.mock import MagicMock
|
|
|
|
import pytest
|
|
import requests
|
|
|
|
from homeassistant.config_entries import ConfigEntryState
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from . import setup_integration
|
|
|
|
from tests.common import MockConfigEntry
|
|
|
|
|
|
async def test_setup_entry(
|
|
hass: HomeAssistant,
|
|
mock_config_entry: MockConfigEntry,
|
|
mock_heater: MagicMock,
|
|
) -> None:
|
|
"""Test successful setup of the integration."""
|
|
await setup_integration(hass, mock_config_entry)
|
|
assert mock_config_entry.state is ConfigEntryState.LOADED
|
|
assert await hass.config_entries.async_unload(mock_config_entry.entry_id)
|
|
assert mock_config_entry.state is ConfigEntryState.NOT_LOADED
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("side_effect", "expected_state"),
|
|
[
|
|
(
|
|
requests.exceptions.ConnectionError("Cannot connect"),
|
|
ConfigEntryState.SETUP_RETRY,
|
|
),
|
|
],
|
|
)
|
|
async def test_setup_entry_fails(
|
|
hass: HomeAssistant,
|
|
mock_config_entry: MockConfigEntry,
|
|
mock_heater: MagicMock,
|
|
side_effect: Exception,
|
|
expected_state: ConfigEntryState,
|
|
) -> None:
|
|
"""Test setup fails correctly for different error types."""
|
|
mock_heater.parse_data.side_effect = side_effect
|
|
await setup_integration(hass, mock_config_entry)
|
|
assert mock_config_entry.state is expected_state
|