refactor: Refactoring most of the project
Some checks failed
🧪 Integration Testing / 🔧 Test Integration (2025.9.4, 3.13) (push) Failing after 24s
Some checks failed
🧪 Integration Testing / 🔧 Test Integration (2025.9.4, 3.13) (push) Failing after 24s
Signed-off-by: Rafal Zielinski <sq4ind@gmail.com>
This commit is contained in:
@@ -1,29 +1,71 @@
|
||||
"""Test config flow for AdGuard Control Hub."""
|
||||
import pytest
|
||||
from homeassistant import config_entries, setup
|
||||
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
|
||||
|
||||
async def test_config_flow_success(hass):
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_config_flow_success(hass: HomeAssistant):
|
||||
"""Test successful config flow."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
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",
|
||||
}
|
||||
|
||||
assert result["type"] == "form"
|
||||
assert result["step_id"] == "user"
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
|
||||
async def test_config_flow_cannot_connect(hass):
|
||||
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."""
|
||||
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",
|
||||
},
|
||||
)
|
||||
from custom_components.adguard_hub.config_flow import CannotConnect
|
||||
|
||||
assert result["type"] == "form"
|
||||
assert result["errors"]["base"] == "cannot_connect"
|
||||
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"
|
||||
|
Reference in New Issue
Block a user