- new per-host service, follows node-agent pattern - 7 new HA event types defined (routing in supervisor — Phase 5) - HeartbeatCheck as pipeline validator (pings /api/, emits ha_websocket_dead) - service.yaml + host configs for piha (ken) and chelsty-infra (chelsty) - test scaffolding with aiohttp/aiosqlite mocks (15/15 passing) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
64 lines
1.8 KiB
Python
64 lines
1.8 KiB
Python
"""Shared fixtures for ha-diag-agent tests."""
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
from pathlib import Path
|
|
from typing import AsyncGenerator
|
|
from unittest.mock import AsyncMock, MagicMock
|
|
|
|
import pytest
|
|
import pytest_asyncio
|
|
|
|
from ha_diag.event_emitter import EventEmitter
|
|
from ha_diag.storage import Storage
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Event dir fixture
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
@pytest.fixture
|
|
def tmp_events_dir(tmp_path: Path) -> Path:
|
|
events = tmp_path / "events"
|
|
events.mkdir()
|
|
return events
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Storage fixture (in-memory via tmp SQLite)
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
@pytest_asyncio.fixture
|
|
async def storage(tmp_path: Path) -> AsyncGenerator[Storage, None]:
|
|
s = Storage(tmp_path / "test.db")
|
|
await s.open()
|
|
yield s
|
|
await s.close()
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# EventEmitter fixture
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
@pytest.fixture
|
|
def emitter(tmp_events_dir: Path) -> EventEmitter:
|
|
return EventEmitter(tmp_events_dir, node_name="test-node")
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Mock HA client fixture
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_ha_client():
|
|
"""HAClient mock that behaves as an async context manager."""
|
|
client = MagicMock()
|
|
client.__aenter__ = AsyncMock(return_value=client)
|
|
client.__aexit__ = AsyncMock(return_value=None)
|
|
client.get_api_status = AsyncMock(return_value={"message": "API running."})
|
|
return client
|