Some checks failed
Code Quality Check / Code Formatting (push) Failing after 21s
Code Quality Check / Security Analysis (push) Failing after 20s
Integration Testing / Integration Tests (2024.12.0, 3.13) (push) Failing after 1m32s
Integration Testing / Integration Tests (2025.9.4, 3.13) (push) Failing after 20s
Signed-off-by: Rafal Zielinski <sq4ind@gmail.com>
149 lines
4.2 KiB
Python
149 lines
4.2 KiB
Python
"""Test configuration for AdGuard Control Hub."""
|
|
import pytest
|
|
from unittest.mock import AsyncMock, MagicMock
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.const import CONF_HOST, CONF_PORT, CONF_USERNAME, CONF_PASSWORD
|
|
|
|
from custom_components.adguard_hub.const import DOMAIN, CONF_SSL, CONF_VERIFY_SSL
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_hass():
|
|
"""Mock Home Assistant."""
|
|
hass = MagicMock()
|
|
hass.data = {}
|
|
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)
|
|
hass.services = MagicMock()
|
|
hass.services.register = MagicMock()
|
|
hass.services.remove = MagicMock()
|
|
hass.services.has_service = MagicMock(return_value=True)
|
|
hass.async_create_task = MagicMock()
|
|
return hass
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_config_entry():
|
|
"""Mock config entry."""
|
|
return ConfigEntry(
|
|
version=1,
|
|
minor_version=1,
|
|
domain=DOMAIN,
|
|
title="AdGuard Control Hub",
|
|
data={
|
|
CONF_HOST: "192.168.1.100",
|
|
CONF_PORT: 3000,
|
|
CONF_USERNAME: "admin",
|
|
CONF_PASSWORD: "password",
|
|
CONF_SSL: False,
|
|
CONF_VERIFY_SSL: True,
|
|
},
|
|
options={},
|
|
source="user",
|
|
unique_id="192.168.1.100:3000",
|
|
discovery_keys={}, # FIXED: Added missing parameter
|
|
subentries_data={}, # FIXED: Added missing parameter
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_api():
|
|
"""Mock AdGuard Home API."""
|
|
api = MagicMock()
|
|
api.host = "192.168.1.100"
|
|
api.port = 3000
|
|
api.base_url = "http://192.168.1.100:3000"
|
|
api.username = "admin"
|
|
api.password = "password"
|
|
api.ssl = False
|
|
api.verify_ssl = True
|
|
|
|
# Mock API methods
|
|
api.test_connection = AsyncMock(return_value=True)
|
|
|
|
api.get_status = AsyncMock(return_value={
|
|
"protection_enabled": True,
|
|
"version": "v0.108.0",
|
|
"running": True,
|
|
"safebrowsing_enabled": True,
|
|
"parental_enabled": False,
|
|
"safesearch_enabled": True,
|
|
"num_filtering_rules": 75000,
|
|
"dns_addresses": ["8.8.8.8", "8.8.4.4"],
|
|
})
|
|
|
|
api.get_clients = AsyncMock(return_value={
|
|
"clients": [
|
|
{
|
|
"name": "test_client",
|
|
"ids": ["192.168.1.200"],
|
|
"filtering_enabled": True,
|
|
"safebrowsing_enabled": True,
|
|
"parental_enabled": False,
|
|
"blocked_services": ["youtube"],
|
|
}
|
|
]
|
|
})
|
|
|
|
api.get_statistics = AsyncMock(return_value={
|
|
"num_dns_queries": 10000,
|
|
"num_blocked_filtering": 2500,
|
|
"avg_processing_time": 1.5,
|
|
})
|
|
|
|
api.set_protection = AsyncMock()
|
|
api.get_client_by_name = AsyncMock(return_value={
|
|
"name": "test_client",
|
|
"ids": ["192.168.1.200"],
|
|
"filtering_enabled": True,
|
|
"blocked_services": ["youtube"],
|
|
})
|
|
api.update_client_blocked_services = AsyncMock()
|
|
api.add_client = AsyncMock()
|
|
api.delete_client = AsyncMock()
|
|
api._request = AsyncMock()
|
|
|
|
return api
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_coordinator():
|
|
"""Mock coordinator."""
|
|
coordinator = MagicMock()
|
|
coordinator.async_request_refresh = AsyncMock()
|
|
coordinator.clients = {
|
|
"test_client": {
|
|
"name": "test_client",
|
|
"ids": ["192.168.1.200"],
|
|
"filtering_enabled": True,
|
|
"blocked_services": ["youtube"],
|
|
}
|
|
}
|
|
coordinator.statistics = {
|
|
"num_dns_queries": 10000,
|
|
"num_blocked_filtering": 2500,
|
|
"avg_processing_time": 1.5,
|
|
}
|
|
coordinator.protection_status = {
|
|
"protection_enabled": True,
|
|
"version": "v0.108.0",
|
|
"running": True,
|
|
"safebrowsing_enabled": True,
|
|
"parental_enabled": False,
|
|
}
|
|
return coordinator
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_aiohttp_session():
|
|
"""Mock aiohttp session."""
|
|
session = AsyncMock()
|
|
response = AsyncMock()
|
|
response.status = 200
|
|
response.json = AsyncMock(return_value={"status": "ok"})
|
|
session.request = AsyncMock(return_value=response)
|
|
session.__aenter__ = AsyncMock(return_value=response)
|
|
session.__aexit__ = AsyncMock()
|
|
return session
|