"""Test the complete AdGuard Control Hub integration.""" import pytest from unittest.mock import MagicMock, patch from homeassistant.exceptions import ConfigEntryNotReady from custom_components.adguard_hub import async_setup_entry, async_unload_entry from custom_components.adguard_hub.const import DOMAIN class TestIntegrationSetup: """Test integration setup and unload.""" @pytest.mark.asyncio async def test_setup_entry_success(self, mock_hass, mock_config_entry, mock_api): """Test successful setup of config entry.""" with patch("custom_components.adguard_hub.AdGuardHomeAPI", return_value=mock_api), patch("custom_components.adguard_hub.async_get_clientsession"): result = await async_setup_entry(mock_hass, mock_config_entry) assert result is True assert DOMAIN in mock_hass.data assert mock_config_entry.entry_id in mock_hass.data[DOMAIN] @pytest.mark.asyncio async def test_setup_entry_connection_failure(self, mock_hass, mock_config_entry): """Test setup failure due to connection error.""" mock_api = MagicMock() mock_api.test_connection = pytest.AsyncMock(return_value=False) with patch("custom_components.adguard_hub.AdGuardHomeAPI", return_value=mock_api), patch("custom_components.adguard_hub.async_get_clientsession"): with pytest.raises(ConfigEntryNotReady): await async_setup_entry(mock_hass, mock_config_entry) @pytest.mark.asyncio async def test_unload_entry_success(self, mock_hass, mock_config_entry): """Test successful unloading of config entry.""" mock_hass.data[DOMAIN] = { mock_config_entry.entry_id: { "coordinator": MagicMock(), "api": MagicMock(), } } result = await async_unload_entry(mock_hass, mock_config_entry) assert result is True assert mock_config_entry.entry_id not in mock_hass.data[DOMAIN]