Files
labFusion/services/service-adapters/tests/test_main.py
GSRN 7005ae6caf
Some checks failed
Integration Tests / performance-tests (push) Has been skipped
LabFusion CI/CD Pipeline / api-docs (push) Successful in 1m47s
LabFusion CI/CD Pipeline / frontend (push) Failing after 2m2s
LabFusion CI/CD Pipeline / integration-tests (push) Has been skipped
Docker Build and Push / build-and-push (push) Failing after 39s
LabFusion CI/CD Pipeline / service-adapters (push) Successful in 56s
LabFusion CI/CD Pipeline / api-gateway (push) Failing after 1m21s
Integration Tests / integration-tests (push) Failing after 35s
Service Adapters (Python FastAPI) / test (3.1) (push) Failing after 13s
Service Adapters (Python FastAPI) / test (3.11) (push) Failing after 43s
Service Adapters (Python FastAPI) / test (3.9) (push) Failing after 44s
Service Adapters (Python FastAPI) / test (3.12) (push) Failing after 47s
Service Adapters (Python FastAPI) / build (push) Has been skipped
fix: Update test configurations and improve Home Assistant route tests
### Summary of Changes
- Added `--asyncio-mode=auto` to `pytest.ini` for better async test handling.
- Corrected patch decorators in `test_general_routes.py` and `test_home_assistant_routes.py` to reference the correct services.
- Enhanced test assertions in `test_home_assistant_routes.py` to verify service availability and response codes.
- Improved clarity and maintainability of test code by applying clean code principles.

### Expected Results
- Improved test execution for asynchronous code and better organization of test cases.
- Enhanced reliability of Home Assistant route tests, ensuring accurate service behavior verification.
2025-09-15 21:39:22 +02:00

51 lines
1.6 KiB
Python

"""
Tests for the main FastAPI application
"""
from fastapi.testclient import TestClient
from main import app
client = TestClient(app)
class TestMainApp:
"""Test the main FastAPI application"""
def test_app_creation(self):
"""Test that the FastAPI app is created correctly"""
assert app is not None
assert app.title == "LabFusion Service Adapters"
assert app.version == "1.0.0"
def test_cors_middleware(self):
"""Test that CORS middleware is properly configured"""
# Test a simple request to verify CORS headers
response = client.get("/")
assert response.status_code == 200
# CORS headers are typically only sent for preflight requests
# For a simple GET request, we just verify the response is successful
assert response.headers.get("content-type") == "application/json"
def test_routers_included(self):
"""Test that all routers are included"""
# Check that all expected routes are available
routes = [route.path for route in app.routes]
# General routes
assert "/" in routes
assert "/health" in routes
assert "/services" in routes
# Other service routes should be included
# (exact paths depend on router definitions)
def test_openapi_docs(self):
"""Test that OpenAPI documentation is available"""
response = client.get("/docs")
assert response.status_code == 200
response = client.get("/openapi.json")
assert response.status_code == 200
assert "openapi" in response.json()