Files
labFusion/services/service-adapters/tests/test_models.py
GSRN 4dc2f147ec
Some checks failed
Docker Build and Push / build-and-push (push) Failing after 37s
LabFusion CI/CD Pipeline / api-gateway (push) Failing after 1m16s
Integration Tests / integration-tests (push) Failing after 58s
Integration Tests / performance-tests (push) Has been skipped
Service Adapters (Python FastAPI) / test (3.1) (push) Failing after 12s
LabFusion CI/CD Pipeline / api-docs (push) Successful in 1m42s
LabFusion CI/CD Pipeline / integration-tests (push) Has been skipped
Service Adapters (Python FastAPI) / test (3.12) (push) Failing after 46s
Service Adapters (Python FastAPI) / test (3.9) (push) Failing after 47s
Service Adapters (Python FastAPI) / build (push) Has been skipped
LabFusion CI/CD Pipeline / frontend (push) Failing after 1m53s
Service Adapters (Python FastAPI) / test (3.11) (push) Failing after 45s
LabFusion CI/CD Pipeline / service-adapters (push) Failing after 28s
fix: Standardize isort command in CI workflows
### Summary of Changes
- Updated the `isort` command in both CI workflows to include the `--profile black` option for consistent code formatting.
- Refactored function definitions in service adapters to improve readability by consolidating parameters into single lines.

### Expected Results
- Enhanced consistency in code formatting checks across CI workflows, ensuring adherence to the Black style guide.
- Improved readability and maintainability of function definitions in service adapters.
2025-09-15 21:16:37 +02:00

151 lines
4.9 KiB
Python

"""
Tests for Pydantic models and schemas
"""
from datetime import datetime
import pytest
from models.schemas import EventData, FrigateEvent, HAAttributes, HAEntity, HealthResponse, RootResponse, ServiceStatus
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"