Some checks failed
Integration Testing / Integration Tests (2024.12.0, 3.11) (push) Failing after 27s
Integration Testing / Integration Tests (2024.12.0, 3.12) (push) Failing after 56s
Integration Testing / Integration Tests (2024.12.0, 3.13) (push) Failing after 1m38s
Integration Testing / Integration Tests (2025.9.4, 3.11) (push) Failing after 19s
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 25s
Code Quality Check / Code Quality Analysis (push) Failing after 20s
Code Quality Check / Security Analysis (push) Failing after 21s
Signed-off-by: Rafal Zielinski <sq4ind@gmail.com>
49 lines
2.0 KiB
Python
49 lines
2.0 KiB
Python
"""Test the complete AdGuard Control Hub integration."""
|
|
import pytest
|
|
from unittest.mock import MagicMock, patch
|
|
from homeassistant.exceptions import ConfigEntryNotReady
|
|
|
|
from custom_components.adguard_hub import async_setup_entry, async_unload_entry
|
|
from custom_components.adguard_hub.const import DOMAIN
|
|
|
|
|
|
class TestIntegrationSetup:
|
|
"""Test integration setup and unload."""
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_setup_entry_success(self, mock_hass, mock_config_entry, mock_api):
|
|
"""Test successful setup of config entry."""
|
|
with patch("custom_components.adguard_hub.AdGuardHomeAPI", return_value=mock_api), patch("custom_components.adguard_hub.async_get_clientsession"):
|
|
|
|
result = await async_setup_entry(mock_hass, mock_config_entry)
|
|
|
|
assert result is True
|
|
assert DOMAIN in mock_hass.data
|
|
assert mock_config_entry.entry_id in mock_hass.data[DOMAIN]
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_setup_entry_connection_failure(self, mock_hass, mock_config_entry):
|
|
"""Test setup failure due to connection error."""
|
|
mock_api = MagicMock()
|
|
mock_api.test_connection = pytest.AsyncMock(return_value=False)
|
|
|
|
with patch("custom_components.adguard_hub.AdGuardHomeAPI", return_value=mock_api), patch("custom_components.adguard_hub.async_get_clientsession"):
|
|
|
|
with pytest.raises(ConfigEntryNotReady):
|
|
await async_setup_entry(mock_hass, mock_config_entry)
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_unload_entry_success(self, mock_hass, mock_config_entry):
|
|
"""Test successful unloading of config entry."""
|
|
mock_hass.data[DOMAIN] = {
|
|
mock_config_entry.entry_id: {
|
|
"coordinator": MagicMock(),
|
|
"api": MagicMock(),
|
|
}
|
|
}
|
|
|
|
result = await async_unload_entry(mock_hass, mock_config_entry)
|
|
|
|
assert result is True
|
|
assert mock_config_entry.entry_id not in mock_hass.data[DOMAIN]
|