"""Test config flow for AdGuard Control Hub.""" import pytest from unittest.mock import AsyncMock, patch from homeassistant import config_entries from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import FlowResultType from custom_components.adguard_hub.const import DOMAIN @pytest.mark.asyncio async def test_config_flow_success(hass: HomeAssistant): """Test successful config flow.""" with patch("custom_components.adguard_hub.config_flow.validate_input") as mock_validate: mock_validate.return_value = { "title": "AdGuard Control Hub (192.168.1.100)", "host": "192.168.1.100", } result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == FlowResultType.FORM assert result["step_id"] == "user" @pytest.mark.asyncio async def test_config_flow_cannot_connect(hass: HomeAssistant): """Test config flow with connection error.""" from custom_components.adguard_hub.config_flow import CannotConnect with patch("custom_components.adguard_hub.config_flow.validate_input") as mock_validate: mock_validate.side_effect = CannotConnect("Connection failed") result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER}, data={ "host": "invalid-host", "port": 3000, "username": "admin", "password": "password", }, ) assert result["type"] == FlowResultType.FORM assert result["errors"]["base"] == "cannot_connect" @pytest.mark.asyncio async def test_config_flow_invalid_auth(hass: HomeAssistant): """Test config flow with authentication error.""" from custom_components.adguard_hub.config_flow import InvalidAuth with patch("custom_components.adguard_hub.config_flow.validate_input") as mock_validate: mock_validate.side_effect = InvalidAuth("Auth failed") result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER}, data={ "host": "192.168.1.100", "port": 3000, "username": "wrong", "password": "wrong", }, ) assert result["type"] == FlowResultType.FORM assert result["errors"]["base"] == "invalid_auth"