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
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:
40
tests/test_api.py
Normal file
40
tests/test_api.py
Normal 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"}
|
Reference in New Issue
Block a user