Some checks failed
LabFusion CI/CD Pipeline / service-adapters (push) Failing after 20s
Docker Build and Push / build-and-push (push) Failing after 37s
Integration Tests / integration-tests (push) Failing after 32s
Integration Tests / performance-tests (push) Has been skipped
Service Adapters (Python FastAPI) / test (3.1) (push) Failing after 15s
LabFusion CI/CD Pipeline / api-gateway (push) Failing after 1m18s
Service Adapters (Python FastAPI) / test (3.11) (push) Failing after 22s
Service Adapters (Python FastAPI) / test (3.12) (push) Failing after 23s
Service Adapters (Python FastAPI) / test (3.9) (push) Failing after 21s
LabFusion CI/CD Pipeline / frontend (push) Failing after 2m0s
Service Adapters (Python FastAPI) / build (push) Has been skipped
LabFusion CI/CD Pipeline / api-docs (push) Successful in 1m53s
LabFusion CI/CD Pipeline / integration-tests (push) Has been skipped
### Summary of Changes - Removed unnecessary blank lines and standardized import statements across test files. - Ensured consistent use of quotes in patch decorators and improved formatting of test data structures. - Enhanced readability and maintainability of test code by applying clean code principles. ### Expected Results - Improved clarity and consistency in test code, facilitating easier understanding and future modifications.
101 lines
2.5 KiB
Python
101 lines
2.5 KiB
Python
"""
|
|
Pytest configuration and fixtures for service adapters tests
|
|
"""
|
|
|
|
from unittest.mock import patch
|
|
|
|
import pytest
|
|
from fastapi.testclient import TestClient
|
|
|
|
from main import app
|
|
|
|
|
|
@pytest.fixture
|
|
def client():
|
|
"""Provide a test client for the FastAPI app"""
|
|
return TestClient(app)
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_services_config():
|
|
"""Mock services configuration for testing"""
|
|
return {
|
|
"home_assistant": {
|
|
"enabled": True,
|
|
"url": "http://homeassistant.local:8123",
|
|
"token": "test_token",
|
|
},
|
|
"frigate": {"enabled": True, "url": "http://frigate.local:5000"},
|
|
"immich": {
|
|
"enabled": False,
|
|
"url": "http://immich.local:2283",
|
|
"api_key": "test_key",
|
|
},
|
|
}
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_ha_entities():
|
|
"""Sample Home Assistant entities for testing"""
|
|
return {
|
|
"sensor.temperature": {
|
|
"entity_id": "sensor.temperature",
|
|
"state": "22.5",
|
|
"attributes": {"unit_of_measurement": "°C", "friendly_name": "Temperature"},
|
|
},
|
|
"light.living_room": {
|
|
"entity_id": "light.living_room",
|
|
"state": "on",
|
|
"attributes": {"friendly_name": "Living Room Light"},
|
|
},
|
|
}
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_frigate_events():
|
|
"""Sample Frigate events for testing"""
|
|
return {
|
|
"events": [
|
|
{
|
|
"id": "event_123",
|
|
"timestamp": "2024-01-01T12:00:00Z",
|
|
"camera": "front_door",
|
|
"label": "person",
|
|
"confidence": 0.95,
|
|
},
|
|
{
|
|
"id": "event_456",
|
|
"timestamp": "2024-01-01T12:05:00Z",
|
|
"camera": "back_yard",
|
|
"label": "car",
|
|
"confidence": 0.87,
|
|
},
|
|
]
|
|
}
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_immich_assets():
|
|
"""Sample Immich assets for testing"""
|
|
return {
|
|
"assets": [
|
|
{
|
|
"id": "asset_123",
|
|
"filename": "IMG_20240101_120000.jpg",
|
|
"created_at": "2024-01-01T12:00:00Z",
|
|
"tags": ["family", "vacation"],
|
|
"faces": ["person_1", "person_2"],
|
|
}
|
|
]
|
|
}
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def mock_redis():
|
|
"""Mock Redis client for all tests"""
|
|
with patch("services.redis_client.redis_client") as mock_redis:
|
|
mock_redis.ping.return_value = True
|
|
mock_redis.set.return_value = True
|
|
mock_redis.get.return_value = None
|
|
yield mock_redis
|