81b9a66ef5
- Delete 4 obsolete unit tests tied to removed git mount/clone models - Update imports and assertions across unit/integration/service tests - Fix Settings defaults (postgres host, JWT props, cookie_samesite) - Add skip guards for PostgreSQL-dependent integration tests - Fix GitService env assertions and HealthMonitor state-change tests - Repair docker/container inspect assertions in test_docker_service - Fix ToolTypeCreate default_port validator ordering bug - Fix check_port_exposed substring false-positive for port 0 - Update test_tool_types_api_extended to use interface_type field Quality gates: pytest 311 passed, 34 skipped; npm typecheck/lint/test 87 passed
50 lines
2.0 KiB
Python
50 lines
2.0 KiB
Python
"""Unit tests for lifecycle hook helpers."""
|
|
|
|
import pytest
|
|
|
|
from src.services.instance.lifecycle_hooks import _derive_title, _should_notify
|
|
|
|
|
|
class TestDeriveTitle:
|
|
"""Tests for _derive_title."""
|
|
|
|
def test_known_event_types(self) -> None:
|
|
assert _derive_title("instance.created") == "Container created"
|
|
assert _derive_title("instance.started") == "Container started"
|
|
assert _derive_title("instance.stopped") == "Container stopped"
|
|
assert _derive_title("instance.restarted") == "Container restarted"
|
|
assert _derive_title("instance.deleted") == "Container deleted"
|
|
assert _derive_title("instance.error") == "Container error"
|
|
assert _derive_title("instance.health_changed") == "Container ready"
|
|
|
|
def test_unknown_event_type(self) -> None:
|
|
assert _derive_title("instance.custom_event") == "Custom Event"
|
|
|
|
|
|
class TestShouldNotify:
|
|
"""Tests for _should_notify filtering."""
|
|
|
|
def test_error_events_are_notified(self) -> None:
|
|
assert _should_notify("instance.error", "error") is True
|
|
assert _should_notify("instance.error", None) is True
|
|
|
|
def test_health_changed_running_is_notified(self) -> None:
|
|
assert _should_notify("instance.health_changed", "running") is True
|
|
|
|
def test_created_started_stopped_restarted_deleted_filtered(self) -> None:
|
|
for event in [
|
|
"instance.created",
|
|
"instance.started",
|
|
"instance.stopped",
|
|
"instance.restarted",
|
|
"instance.deleted",
|
|
]:
|
|
assert _should_notify(event, "pending") is False
|
|
assert _should_notify(event, "running") is False
|
|
assert _should_notify(event, None) is False
|
|
|
|
def test_health_changed_non_running_filtered(self) -> None:
|
|
assert _should_notify("instance.health_changed", "unhealthy") is False
|
|
assert _should_notify("instance.health_changed", "starting") is False
|
|
assert _should_notify("instance.health_changed", None) is False
|