"""Test configuration and fixtures.""" import pytest from unittest.mock import AsyncMock, MagicMock from homeassistant.core import HomeAssistant from homeassistant.config_entries import ConfigEntry, SOURCE_USER from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT, CONF_USERNAME from custom_components.adguard_hub.api import AdGuardHomeAPI from custom_components.adguard_hub.const import DOMAIN @pytest.fixture(autouse=True) def auto_enable_custom_integrations(enable_custom_integrations): """Enable custom integrations for all tests.""" yield @pytest.fixture def mock_config_entry(): """Mock config entry for testing.""" return ConfigEntry( version=1, minor_version=1, domain=DOMAIN, title="Test AdGuard Control Hub", data={ CONF_HOST: "192.168.1.100", CONF_PORT: 3000, CONF_USERNAME: "admin", CONF_PASSWORD: "password", }, options={}, source=SOURCE_USER, entry_id="test_entry_id", unique_id="192.168.1.100:3000", ) @pytest.fixture def mock_api(): """Mock AdGuard Home API.""" api = MagicMock(spec=AdGuardHomeAPI) api.host = "192.168.1.100" api.port = 3000 api.test_connection = AsyncMock(return_value=True) api.get_status = AsyncMock(return_value={ "protection_enabled": True, "version": "v0.107.0", "dns_port": 53, "running": True, }) api.get_clients = AsyncMock(return_value={ "clients": [ { "name": "test_client", "ids": ["192.168.1.50"], "filtering_enabled": True, "blocked_services": {"ids": ["youtube"]}, } ] }) api.get_statistics = AsyncMock(return_value={ "num_dns_queries": 10000, "num_blocked_filtering": 1500, "avg_processing_time": 2.5, "filtering_rules_count": 75000, }) api.get_client_by_name = AsyncMock(return_value={ "name": "test_client", "ids": ["192.168.1.50"], "filtering_enabled": True, "blocked_services": {"ids": ["youtube"]}, }) api.set_protection = AsyncMock(return_value={"success": True}) return api @pytest.fixture def mock_hass(): """Mock Home Assistant instance.""" hass = MagicMock(spec=HomeAssistant) hass.data = {} hass.services = MagicMock() hass.services.has_service = MagicMock(return_value=False) hass.services.register = MagicMock() hass.services.remove = MagicMock() hass.config_entries = MagicMock() hass.config_entries.async_forward_entry_setups = AsyncMock(return_value=True) hass.config_entries.async_unload_platforms = AsyncMock(return_value=True) return hass