Files
adguard-control-hub/tests/test_api.py
Rafal Zielinski 554b8ac16b
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
refactor: another refactor
Signed-off-by: Rafal Zielinski <sq4ind@gmail.com>
2025-09-28 17:01:21 +01:00

54 lines
1.8 KiB
Python

"""Test API functionality."""
import pytest
from unittest.mock import AsyncMock, MagicMock
from custom_components.adguard_hub.api import AdGuardHomeAPI
class TestAdGuardHomeAPI:
"""Test the AdGuard Home API wrapper."""
def test_api_initialization(self):
"""Test API initialization."""
api = AdGuardHomeAPI(
host="192.168.1.100",
port=3000,
username="admin",
password="password",
ssl=True,
)
assert api.host == "192.168.1.100"
assert api.port == 3000
assert api.username == "admin"
assert api.password == "password"
assert api.ssl is True
assert api.base_url == "https://192.168.1.100:3000"
@pytest.mark.asyncio
async def test_api_context_manager(self):
"""Test API as async context manager."""
async with AdGuardHomeAPI(host="192.168.1.100", port=3000) as api:
assert api is not None
assert api.host == "192.168.1.100"
assert api.port == 3000
@pytest.mark.asyncio
async def test_test_connection_success(self):
"""Test successful connection test."""
session = MagicMock()
response = MagicMock()
response.status = 200
response.json = AsyncMock(return_value={"protection_enabled": True})
response.raise_for_status = MagicMock()
response.content_length = 100
context_manager = MagicMock()
context_manager.__aenter__ = AsyncMock(return_value=response)
context_manager.__aexit__ = AsyncMock(return_value=None)
session.request = MagicMock(return_value=context_manager)
api = AdGuardHomeAPI(host="192.168.1.100", session=session)
result = await api.test_connection()
assert result is True