70 lines
1.9 KiB
Python
70 lines
1.9 KiB
Python
"""Test configuration for AdGuard Control Hub integration."""
|
|
import pytest
|
|
from unittest.mock import AsyncMock, MagicMock, patch
|
|
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
|
|
|
from custom_components.adguard_control_hub.const import (
|
|
CONF_HOST,
|
|
CONF_PASSWORD,
|
|
CONF_PORT,
|
|
CONF_SSL,
|
|
CONF_USERNAME,
|
|
CONF_VERIFY_SSL,
|
|
DOMAIN,
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_adguard_api():
|
|
"""Mock AdGuard API client."""
|
|
mock_api = MagicMock()
|
|
mock_api.get_status = AsyncMock(return_value={
|
|
"version": "0.107.50",
|
|
"protection_enabled": True,
|
|
"filtering_enabled": True,
|
|
"safebrowsing_enabled": True,
|
|
"parental_enabled": True,
|
|
"safesearch_enabled": True,
|
|
"querylog_enabled": True,
|
|
})
|
|
mock_api.get_stats = AsyncMock(return_value={
|
|
"num_dns_queries": 1000,
|
|
"num_blocked_filtering": 200,
|
|
"avg_processing_time": 1.5,
|
|
"num_replaced_safebrowsing": 1500,
|
|
})
|
|
mock_api.get_clients = AsyncMock(return_value={
|
|
"clients": [],
|
|
"auto_clients": [],
|
|
})
|
|
mock_api.set_protection = AsyncMock()
|
|
mock_api.set_filtering = AsyncMock()
|
|
mock_api.set_safebrowsing = AsyncMock()
|
|
mock_api.set_parental_control = AsyncMock()
|
|
mock_api.set_safe_search = AsyncMock()
|
|
mock_api.set_query_log = AsyncMock()
|
|
mock_api.test_connection = AsyncMock(return_value=True)
|
|
return mock_api
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_config_entry():
|
|
"""Mock config entry."""
|
|
return {
|
|
CONF_HOST: "192.168.1.100",
|
|
CONF_PORT: 3000,
|
|
CONF_USERNAME: "admin",
|
|
CONF_PASSWORD: "password",
|
|
CONF_SSL: False,
|
|
CONF_VERIFY_SSL: True,
|
|
}
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_setup_entry():
|
|
"""Mock setup entry."""
|
|
with patch("custom_components.adguard_control_hub.AdGuardHomeAPI") as mock_api_class:
|
|
yield mock_api_class
|