Files
adguard-control-hub/tests/test_config_flow.py
Rafal Zielinski 4553eb454a
Some checks failed
🧪 Integration Testing / 🔧 Test Integration (2025.9.4, 3.13) (push) Failing after 24s
refactor: Refactoring most of the project
Signed-off-by: Rafal Zielinski <sq4ind@gmail.com>
2025-09-28 15:34:46 +01:00

72 lines
2.5 KiB
Python

"""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"