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,10 +1,11 @@
"""
Tests for general API routes
"""
import pytest
from fastapi.testclient import TestClient
from unittest.mock import patch
from fastapi.testclient import TestClient
from main import app
client = TestClient(app)
@@ -17,7 +18,7 @@ class TestGeneralRoutes:
"""Test the root endpoint"""
response = client.get("/")
assert response.status_code == 200
data = response.json()
assert data["message"] == "LabFusion Service Adapters API"
assert data["version"] == "1.0.0"
@@ -26,40 +27,34 @@ class TestGeneralRoutes:
"""Test the health check endpoint"""
response = client.get("/health")
assert response.status_code == 200
data = response.json()
assert data["status"] == "healthy"
assert "timestamp" in data
# Verify timestamp is in ISO format
assert "T" in data["timestamp"] or "Z" in data["timestamp"]
@patch('services.config.SERVICES')
@patch("services.config.SERVICES")
def test_get_services(self, mock_services):
"""Test the get services endpoint"""
# Mock the services configuration
mock_services.items.return_value = [
("home_assistant", {
"enabled": True,
"url": "http://homeassistant.local:8123"
}),
("frigate", {
"enabled": True,
"url": "http://frigate.local:5000"
}),
("immich", {
"enabled": False,
"url": "http://immich.local:2283"
})
(
"home_assistant",
{"enabled": True, "url": "http://homeassistant.local:8123"},
),
("frigate", {"enabled": True, "url": "http://frigate.local:5000"}),
("immich", {"enabled": False, "url": "http://immich.local:2283"}),
]
response = client.get("/services")
assert response.status_code == 200
data = response.json()
assert "home_assistant" in data
assert "frigate" in data
assert "immich" in data
# Check service status structure
ha_service = data["home_assistant"]
assert ha_service["enabled"] is True
@@ -70,7 +65,7 @@ class TestGeneralRoutes:
"""Test that health check returns proper response model"""
response = client.get("/health")
data = response.json()
# Verify all required fields are present
required_fields = ["status", "timestamp"]
for field in required_fields:
@@ -80,7 +75,7 @@ class TestGeneralRoutes:
"""Test that root endpoint returns proper response model"""
response = client.get("/")
data = response.json()
# Verify all required fields are present
required_fields = ["message", "version"]
for field in required_fields: