Initial commit
Some checks failed
🧪 Integration Testing / 🔧 Test Integration (2023.12.0, 3.11) (push) Successful in 2m11s
🧪 Integration Testing / 🔧 Test Integration (2023.12.0, 3.12) (push) Successful in 2m2s
🧪 Integration Testing / 🔧 Test Integration (2024.1.0, 3.11) (push) Successful in 1m4s
🧪 Integration Testing / 🔧 Test Integration (2024.1.0, 3.12) (push) Successful in 1m19s
🛡️ Code Quality & Security Check / 🔍 Code Quality Analysis (push) Failing after 56s

Signed-off-by: Rafal Zielinski <sq4ind@gmail.com>
This commit is contained in:
2025-09-28 13:30:43 +01:00
commit e29f7c025b
22 changed files with 1148 additions and 0 deletions

1
tests/__init__.py Normal file
View File

@@ -0,0 +1 @@
"""Tests for AdGuard Control Hub."""

40
tests/test_api.py Normal file
View File

@@ -0,0 +1,40 @@
"""Test API functionality."""
import pytest
from unittest.mock import AsyncMock, MagicMock
from custom_components.adguard_hub.api import AdGuardHomeAPI
@pytest.fixture
def mock_session():
"""Mock aiohttp session."""
session = MagicMock()
response = MagicMock()
response.raise_for_status = MagicMock()
response.json = AsyncMock(return_value={"status": "ok"})
response.status = 200
response.content_length = 100
session.request = AsyncMock(return_value=response)
return session
async def test_api_connection(mock_session):
"""Test API connection."""
api = AdGuardHomeAPI(
host="test-host",
port=3000,
username="admin",
password="password",
session=mock_session
)
result = await api.test_connection()
assert result is True
async def test_api_get_status(mock_session):
"""Test getting status."""
api = AdGuardHomeAPI(
host="test-host",
port=3000,
session=mock_session
)
status = await api.get_status()
assert status == {"status": "ok"}

29
tests/test_config_flow.py Normal file
View File

@@ -0,0 +1,29 @@
"""Test config flow for AdGuard Control Hub."""
import pytest
from homeassistant import config_entries, setup
from custom_components.adguard_hub.const import DOMAIN
async def test_config_flow_success(hass):
"""Test successful config flow."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["type"] == "form"
assert result["step_id"] == "user"
async def test_config_flow_cannot_connect(hass):
"""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",
},
)
assert result["type"] == "form"
assert result["errors"]["base"] == "cannot_connect"