fix: Fix CI/CD issues and enhance integration
Some checks failed
Integration Testing / Integration Tests (2024.12.0, 3.11) (push) Failing after 22s
Integration Testing / Integration Tests (2024.12.0, 3.12) (push) Failing after 21s
Integration Testing / Integration Tests (2024.12.0, 3.13) (push) Failing after 1m32s
Integration Testing / Integration Tests (2025.9.4, 3.11) (push) Failing after 15s
Integration Testing / Integration Tests (2025.9.4, 3.12) (push) Failing after 20s
Integration Testing / Integration Tests (2025.9.4, 3.13) (push) Failing after 20s
Some checks failed
Integration Testing / Integration Tests (2024.12.0, 3.11) (push) Failing after 22s
Integration Testing / Integration Tests (2024.12.0, 3.12) (push) Failing after 21s
Integration Testing / Integration Tests (2024.12.0, 3.13) (push) Failing after 1m32s
Integration Testing / Integration Tests (2025.9.4, 3.11) (push) Failing after 15s
Integration Testing / Integration Tests (2025.9.4, 3.12) (push) Failing after 20s
Integration Testing / Integration Tests (2025.9.4, 3.13) (push) Failing after 20s
Signed-off-by: Rafal Zielinski <sq4ind@gmail.com>
This commit is contained in:
@@ -6,7 +6,7 @@ from homeassistant.config_entries import ConfigEntry, SOURCE_USER
|
||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT, CONF_USERNAME
|
||||
|
||||
from custom_components.adguard_hub.api import AdGuardHomeAPI
|
||||
from custom_components.adguard_hub.const import DOMAIN
|
||||
from custom_components.adguard_hub.const import DOMAIN, CONF_SSL, CONF_VERIFY_SSL
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
@@ -28,11 +28,15 @@ def mock_config_entry():
|
||||
CONF_PORT: 3000,
|
||||
CONF_USERNAME: "admin",
|
||||
CONF_PASSWORD: "password",
|
||||
CONF_SSL: False,
|
||||
CONF_VERIFY_SSL: True,
|
||||
},
|
||||
options={},
|
||||
source=SOURCE_USER,
|
||||
entry_id="test_entry_id",
|
||||
unique_id="192.168.1.100:3000",
|
||||
discovery_keys=set(), # Added required parameter
|
||||
subentries_data={}, # Added required parameter
|
||||
)
|
||||
|
||||
|
||||
@@ -42,39 +46,140 @@ def mock_api():
|
||||
api = MagicMock(spec=AdGuardHomeAPI)
|
||||
api.host = "192.168.1.100"
|
||||
api.port = 3000
|
||||
api.ssl = False
|
||||
api.verify_ssl = True
|
||||
|
||||
# Mock successful connection
|
||||
api.test_connection = AsyncMock(return_value=True)
|
||||
|
||||
# Mock status response
|
||||
api.get_status = AsyncMock(return_value={
|
||||
"protection_enabled": True,
|
||||
"version": "v0.107.0",
|
||||
"dns_port": 53,
|
||||
"running": True,
|
||||
"dns_addresses": ["192.168.1.100:53"],
|
||||
"bootstrap_dns": ["1.1.1.1", "8.8.8.8"],
|
||||
"upstream_dns": ["1.1.1.1", "8.8.8.8", "1.0.0.1", "8.8.4.4"],
|
||||
"safebrowsing_enabled": True,
|
||||
"parental_enabled": False,
|
||||
"safesearch_enabled": False,
|
||||
"dhcp_available": False,
|
||||
})
|
||||
|
||||
# Mock clients response
|
||||
api.get_clients = AsyncMock(return_value={
|
||||
"clients": [
|
||||
{
|
||||
"name": "test_client",
|
||||
"ids": ["192.168.1.50"],
|
||||
"filtering_enabled": True,
|
||||
"blocked_services": {"ids": ["youtube"]},
|
||||
"safebrowsing_enabled": False,
|
||||
"parental_enabled": False,
|
||||
"safesearch_enabled": False,
|
||||
"use_global_settings": True,
|
||||
"use_global_blocked_services": True,
|
||||
"blocked_services": {"ids": ["youtube", "gaming"]},
|
||||
},
|
||||
{
|
||||
"name": "test_client_2",
|
||||
"ids": ["192.168.1.51"],
|
||||
"filtering_enabled": False,
|
||||
"safebrowsing_enabled": True,
|
||||
"parental_enabled": True,
|
||||
"safesearch_enabled": False,
|
||||
"use_global_settings": False,
|
||||
"blocked_services": {"ids": ["netflix"]},
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
# Mock statistics response
|
||||
api.get_statistics = AsyncMock(return_value={
|
||||
"num_dns_queries": 10000,
|
||||
"num_blocked_filtering": 1500,
|
||||
"num_dns_queries_today": 5000,
|
||||
"num_blocked_filtering_today": 750,
|
||||
"num_replaced_safebrowsing": 50,
|
||||
"num_replaced_parental": 25,
|
||||
"num_replaced_safesearch": 10,
|
||||
"avg_processing_time": 2.5,
|
||||
"filtering_rules_count": 75000,
|
||||
})
|
||||
|
||||
# Mock client operations
|
||||
api.get_client_by_name = AsyncMock(return_value={
|
||||
"name": "test_client",
|
||||
"ids": ["192.168.1.50"],
|
||||
"filtering_enabled": True,
|
||||
"blocked_services": {"ids": ["youtube"]},
|
||||
})
|
||||
|
||||
api.add_client = AsyncMock(return_value={"success": True})
|
||||
api.update_client = AsyncMock(return_value={"success": True})
|
||||
api.delete_client = AsyncMock(return_value={"success": True})
|
||||
api.update_client_blocked_services = AsyncMock(return_value={"success": True})
|
||||
api.set_protection = AsyncMock(return_value={"success": True})
|
||||
api.close = AsyncMock(return_value=None)
|
||||
|
||||
return api
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_coordinator(mock_api):
|
||||
"""Mock coordinator with test data."""
|
||||
from custom_components.adguard_hub import AdGuardControlHubCoordinator
|
||||
|
||||
coordinator = MagicMock(spec=AdGuardControlHubCoordinator)
|
||||
coordinator.last_update_success = True
|
||||
coordinator.api = mock_api
|
||||
|
||||
# Mock clients data
|
||||
coordinator.clients = {
|
||||
"test_client": {
|
||||
"name": "test_client",
|
||||
"ids": ["192.168.1.50"],
|
||||
"filtering_enabled": True,
|
||||
"blocked_services": {"ids": ["youtube"]},
|
||||
},
|
||||
"test_client_2": {
|
||||
"name": "test_client_2",
|
||||
"ids": ["192.168.1.51"],
|
||||
"filtering_enabled": False,
|
||||
"blocked_services": {"ids": ["netflix"]},
|
||||
}
|
||||
}
|
||||
|
||||
# Mock statistics data
|
||||
coordinator.statistics = {
|
||||
"num_dns_queries": 10000,
|
||||
"num_blocked_filtering": 1500,
|
||||
"avg_processing_time": 2.5,
|
||||
"filtering_rules_count": 75000,
|
||||
}
|
||||
|
||||
# Mock protection status
|
||||
coordinator.protection_status = {
|
||||
"protection_enabled": True,
|
||||
"version": "v0.107.0",
|
||||
"dns_port": 53,
|
||||
"running": True,
|
||||
"safebrowsing_enabled": True,
|
||||
"parental_enabled": False,
|
||||
"safesearch_enabled": False,
|
||||
}
|
||||
|
||||
coordinator.data = {
|
||||
"clients": coordinator.clients,
|
||||
"statistics": coordinator.statistics,
|
||||
"status": coordinator.protection_status,
|
||||
}
|
||||
|
||||
coordinator.async_request_refresh = AsyncMock()
|
||||
|
||||
return coordinator
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_hass():
|
||||
"""Mock Home Assistant instance."""
|
||||
@@ -88,3 +193,25 @@ def mock_hass():
|
||||
hass.config_entries.async_forward_entry_setups = AsyncMock(return_value=True)
|
||||
hass.config_entries.async_unload_platforms = AsyncMock(return_value=True)
|
||||
return hass
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_aiohttp_session():
|
||||
"""Mock aiohttp session."""
|
||||
session = MagicMock()
|
||||
response = MagicMock()
|
||||
response.raise_for_status = MagicMock()
|
||||
response.json = AsyncMock(return_value={"status": "ok"})
|
||||
response.text = AsyncMock(return_value="OK")
|
||||
response.status = 200
|
||||
response.content_length = 100
|
||||
|
||||
# Mock async context manager
|
||||
context_manager = MagicMock()
|
||||
context_manager.__aenter__ = AsyncMock(return_value=response)
|
||||
context_manager.__aexit__ = AsyncMock(return_value=None)
|
||||
|
||||
session.request = MagicMock(return_value=context_manager)
|
||||
session.close = AsyncMock()
|
||||
|
||||
return session
|
||||
|
Reference in New Issue
Block a user