chore: Add test reports directory creation step in CI workflows
Some checks failed
Docker Build and Push / build-and-push (push) Failing after 36s
LabFusion CI/CD Pipeline / api-gateway (push) Failing after 1m11s
Integration Tests / integration-tests (push) Failing after 29s
LabFusion CI/CD Pipeline / api-docs (push) Successful in 1m42s
Integration Tests / performance-tests (push) Has been skipped
Service Adapters (Python FastAPI) / test (3.1) (push) Failing after 11s
Service Adapters (Python FastAPI) / test (3.11) (push) Failing after 19s
LabFusion CI/CD Pipeline / frontend (push) Failing after 1m50s
LabFusion CI/CD Pipeline / integration-tests (push) Has been skipped
Service Adapters (Python FastAPI) / test (3.12) (push) Failing after 20s
Service Adapters (Python FastAPI) / test (3.9) (push) Failing after 21s
Service Adapters (Python FastAPI) / build (push) Has been skipped
LabFusion CI/CD Pipeline / service-adapters (push) Failing after 20s
Some checks failed
Docker Build and Push / build-and-push (push) Failing after 36s
LabFusion CI/CD Pipeline / api-gateway (push) Failing after 1m11s
Integration Tests / integration-tests (push) Failing after 29s
LabFusion CI/CD Pipeline / api-docs (push) Successful in 1m42s
Integration Tests / performance-tests (push) Has been skipped
Service Adapters (Python FastAPI) / test (3.1) (push) Failing after 11s
Service Adapters (Python FastAPI) / test (3.11) (push) Failing after 19s
LabFusion CI/CD Pipeline / frontend (push) Failing after 1m50s
LabFusion CI/CD Pipeline / integration-tests (push) Has been skipped
Service Adapters (Python FastAPI) / test (3.12) (push) Failing after 20s
Service Adapters (Python FastAPI) / test (3.9) (push) Failing after 21s
Service Adapters (Python FastAPI) / build (push) Has been skipped
LabFusion CI/CD Pipeline / service-adapters (push) Failing after 20s
### Summary of Changes - Introduced a step to create a `tests/reports` directory in both CI workflows for Service Adapters and the main CI configuration. - This ensures that test reports have a designated location for output, improving organization and accessibility. ### Expected Results - Enhanced structure for test report generation, facilitating easier access to test results and improving overall CI workflow clarity.
This commit is contained in:
181
services/service-adapters/tests/test_models.py
Normal file
181
services/service-adapters/tests/test_models.py
Normal file
@@ -0,0 +1,181 @@
|
||||
"""
|
||||
Tests for Pydantic models and schemas
|
||||
"""
|
||||
import pytest
|
||||
from datetime import datetime
|
||||
from typing import Dict, Any
|
||||
|
||||
from models.schemas import (
|
||||
ServiceStatus, HAAttributes, HAEntity, HAEntitiesResponse,
|
||||
FrigateEvent, FrigateEventsResponse, ImmichAsset, ImmichAssetsResponse,
|
||||
EventData, EventResponse, Event, EventsResponse,
|
||||
HealthResponse, RootResponse
|
||||
)
|
||||
|
||||
|
||||
class TestServiceStatus:
|
||||
"""Test ServiceStatus model"""
|
||||
|
||||
def test_service_status_creation(self):
|
||||
"""Test creating a ServiceStatus instance"""
|
||||
service = ServiceStatus(
|
||||
enabled=True,
|
||||
url="http://example.com",
|
||||
status="healthy"
|
||||
)
|
||||
assert service.enabled is True
|
||||
assert service.url == "http://example.com"
|
||||
assert service.status == "healthy"
|
||||
|
||||
def test_service_status_validation(self):
|
||||
"""Test ServiceStatus validation"""
|
||||
# Valid data
|
||||
service = ServiceStatus(
|
||||
enabled=False,
|
||||
url="https://api.example.com",
|
||||
status="unhealthy"
|
||||
)
|
||||
assert service.enabled is False
|
||||
|
||||
def test_service_status_required_fields(self):
|
||||
"""Test that required fields are enforced"""
|
||||
with pytest.raises(ValueError):
|
||||
ServiceStatus() # Missing required fields
|
||||
|
||||
|
||||
class TestHAAttributes:
|
||||
"""Test HAAttributes model"""
|
||||
|
||||
def test_ha_attributes_creation(self):
|
||||
"""Test creating HAAttributes instance"""
|
||||
attrs = HAAttributes(
|
||||
unit_of_measurement="°C",
|
||||
friendly_name="Living Room Temperature"
|
||||
)
|
||||
assert attrs.unit_of_measurement == "°C"
|
||||
assert attrs.friendly_name == "Living Room Temperature"
|
||||
|
||||
def test_ha_attributes_optional_fields(self):
|
||||
"""Test that fields are optional"""
|
||||
attrs = HAAttributes()
|
||||
assert attrs.unit_of_measurement is None
|
||||
assert attrs.friendly_name is None
|
||||
|
||||
|
||||
class TestHAEntity:
|
||||
"""Test HAEntity model"""
|
||||
|
||||
def test_ha_entity_creation(self):
|
||||
"""Test creating HAEntity instance"""
|
||||
attributes = HAAttributes(
|
||||
unit_of_measurement="°C",
|
||||
friendly_name="Temperature"
|
||||
)
|
||||
entity = HAEntity(
|
||||
entity_id="sensor.temperature",
|
||||
state="22.5",
|
||||
attributes=attributes
|
||||
)
|
||||
assert entity.entity_id == "sensor.temperature"
|
||||
assert entity.state == "22.5"
|
||||
assert entity.attributes.unit_of_measurement == "°C"
|
||||
|
||||
|
||||
class TestFrigateEvent:
|
||||
"""Test FrigateEvent model"""
|
||||
|
||||
def test_frigate_event_creation(self):
|
||||
"""Test creating FrigateEvent instance"""
|
||||
event = FrigateEvent(
|
||||
id="event_123",
|
||||
timestamp="2024-01-01T12:00:00Z",
|
||||
camera="front_door",
|
||||
label="person",
|
||||
confidence=0.95
|
||||
)
|
||||
assert event.id == "event_123"
|
||||
assert event.camera == "front_door"
|
||||
assert event.label == "person"
|
||||
assert event.confidence == 0.95
|
||||
|
||||
def test_frigate_event_confidence_validation(self):
|
||||
"""Test confidence validation (0-1 range)"""
|
||||
# Valid confidence
|
||||
event = FrigateEvent(
|
||||
id="event_123",
|
||||
timestamp="2024-01-01T12:00:00Z",
|
||||
camera="front_door",
|
||||
label="person",
|
||||
confidence=0.5
|
||||
)
|
||||
assert event.confidence == 0.5
|
||||
|
||||
# Invalid confidence (too high)
|
||||
with pytest.raises(ValueError):
|
||||
FrigateEvent(
|
||||
id="event_123",
|
||||
timestamp="2024-01-01T12:00:00Z",
|
||||
camera="front_door",
|
||||
label="person",
|
||||
confidence=1.5
|
||||
)
|
||||
|
||||
# Invalid confidence (negative)
|
||||
with pytest.raises(ValueError):
|
||||
FrigateEvent(
|
||||
id="event_123",
|
||||
timestamp="2024-01-01T12:00:00Z",
|
||||
camera="front_door",
|
||||
label="person",
|
||||
confidence=-0.1
|
||||
)
|
||||
|
||||
|
||||
class TestEventData:
|
||||
"""Test EventData model"""
|
||||
|
||||
def test_event_data_creation(self):
|
||||
"""Test creating EventData instance"""
|
||||
event = EventData(
|
||||
service="home_assistant",
|
||||
event_type="state_changed",
|
||||
metadata={"entity_id": "sensor.temperature", "new_state": "22.5"}
|
||||
)
|
||||
assert event.service == "home_assistant"
|
||||
assert event.event_type == "state_changed"
|
||||
assert event.metadata["entity_id"] == "sensor.temperature"
|
||||
|
||||
def test_event_data_default_metadata(self):
|
||||
"""Test default metadata is empty dict"""
|
||||
event = EventData(
|
||||
service="test_service",
|
||||
event_type="test_event"
|
||||
)
|
||||
assert event.metadata == {}
|
||||
|
||||
|
||||
class TestHealthResponse:
|
||||
"""Test HealthResponse model"""
|
||||
|
||||
def test_health_response_creation(self):
|
||||
"""Test creating HealthResponse instance"""
|
||||
timestamp = datetime.now().isoformat()
|
||||
health = HealthResponse(
|
||||
status="healthy",
|
||||
timestamp=timestamp
|
||||
)
|
||||
assert health.status == "healthy"
|
||||
assert health.timestamp == timestamp
|
||||
|
||||
|
||||
class TestRootResponse:
|
||||
"""Test RootResponse model"""
|
||||
|
||||
def test_root_response_creation(self):
|
||||
"""Test creating RootResponse instance"""
|
||||
response = RootResponse(
|
||||
message="Test API",
|
||||
version="1.0.0"
|
||||
)
|
||||
assert response.message == "Test API"
|
||||
assert response.version == "1.0.0"
|
||||
Reference in New Issue
Block a user