fix: Clean up and standardize test code formatting
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.
This commit is contained in:
GSRN
2025-09-15 21:12:15 +02:00
parent 64d4e405c5
commit 8c37bff103
6 changed files with 82 additions and 114 deletions

View File

@@ -1,16 +1,13 @@
"""
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
)
from datetime import datetime
import pytest
from models.schemas import (EventData, FrigateEvent, HAAttributes, HAEntity,
HealthResponse, RootResponse, ServiceStatus)
class TestServiceStatus:
@@ -19,9 +16,7 @@ class TestServiceStatus:
def test_service_status_creation(self):
"""Test creating a ServiceStatus instance"""
service = ServiceStatus(
enabled=True,
url="http://example.com",
status="healthy"
enabled=True, url="http://example.com", status="healthy"
)
assert service.enabled is True
assert service.url == "http://example.com"
@@ -31,9 +26,7 @@ class TestServiceStatus:
"""Test ServiceStatus validation"""
# Valid data
service = ServiceStatus(
enabled=False,
url="https://api.example.com",
status="unhealthy"
enabled=False, url="https://api.example.com", status="unhealthy"
)
assert service.enabled is False
@@ -49,8 +42,7 @@ class TestHAAttributes:
def test_ha_attributes_creation(self):
"""Test creating HAAttributes instance"""
attrs = HAAttributes(
unit_of_measurement="°C",
friendly_name="Living Room Temperature"
unit_of_measurement="°C", friendly_name="Living Room Temperature"
)
assert attrs.unit_of_measurement == "°C"
assert attrs.friendly_name == "Living Room Temperature"
@@ -67,14 +59,9 @@ class TestHAEntity:
def test_ha_entity_creation(self):
"""Test creating HAEntity instance"""
attributes = HAAttributes(
unit_of_measurement="°C",
friendly_name="Temperature"
)
attributes = HAAttributes(unit_of_measurement="°C", friendly_name="Temperature")
entity = HAEntity(
entity_id="sensor.temperature",
state="22.5",
attributes=attributes
entity_id="sensor.temperature", state="22.5", attributes=attributes
)
assert entity.entity_id == "sensor.temperature"
assert entity.state == "22.5"
@@ -91,7 +78,7 @@ class TestFrigateEvent:
timestamp="2024-01-01T12:00:00Z",
camera="front_door",
label="person",
confidence=0.95
confidence=0.95,
)
assert event.id == "event_123"
assert event.camera == "front_door"
@@ -106,7 +93,7 @@ class TestFrigateEvent:
timestamp="2024-01-01T12:00:00Z",
camera="front_door",
label="person",
confidence=0.5
confidence=0.5,
)
assert event.confidence == 0.5
@@ -117,7 +104,7 @@ class TestFrigateEvent:
timestamp="2024-01-01T12:00:00Z",
camera="front_door",
label="person",
confidence=1.5
confidence=1.5,
)
# Invalid confidence (negative)
@@ -127,7 +114,7 @@ class TestFrigateEvent:
timestamp="2024-01-01T12:00:00Z",
camera="front_door",
label="person",
confidence=-0.1
confidence=-0.1,
)
@@ -139,7 +126,7 @@ class TestEventData:
event = EventData(
service="home_assistant",
event_type="state_changed",
metadata={"entity_id": "sensor.temperature", "new_state": "22.5"}
metadata={"entity_id": "sensor.temperature", "new_state": "22.5"},
)
assert event.service == "home_assistant"
assert event.event_type == "state_changed"
@@ -147,10 +134,7 @@ class TestEventData:
def test_event_data_default_metadata(self):
"""Test default metadata is empty dict"""
event = EventData(
service="test_service",
event_type="test_event"
)
event = EventData(service="test_service", event_type="test_event")
assert event.metadata == {}
@@ -160,10 +144,7 @@ class TestHealthResponse:
def test_health_response_creation(self):
"""Test creating HealthResponse instance"""
timestamp = datetime.now().isoformat()
health = HealthResponse(
status="healthy",
timestamp=timestamp
)
health = HealthResponse(status="healthy", timestamp=timestamp)
assert health.status == "healthy"
assert health.timestamp == timestamp
@@ -173,9 +154,6 @@ class TestRootResponse:
def test_root_response_creation(self):
"""Test creating RootResponse instance"""
response = RootResponse(
message="Test API",
version="1.0.0"
)
response = RootResponse(message="Test API", version="1.0.0")
assert response.message == "Test API"
assert response.version == "1.0.0"