test: Update service health check tests to include mock responses
Some checks failed
Integration Tests / integration-tests (push) Failing after 20s
Service Adapters (Python FastAPI) / test (3.11) (push) Failing after 20s
Integration Tests / performance-tests (push) Has been skipped
Service Adapters (Python FastAPI) / test (3.12) (push) Failing after 21s
Service Adapters (Python FastAPI) / test (3.13) (push) Failing after 22s
Service Adapters (Python FastAPI) / build (push) Has been skipped
Some checks failed
Integration Tests / integration-tests (push) Failing after 20s
Service Adapters (Python FastAPI) / test (3.11) (push) Failing after 20s
Integration Tests / performance-tests (push) Has been skipped
Service Adapters (Python FastAPI) / test (3.12) (push) Failing after 21s
Service Adapters (Python FastAPI) / test (3.13) (push) Failing after 22s
Service Adapters (Python FastAPI) / build (push) Has been skipped
### Summary of Changes - Modified the `test_get_services` method to patch the health check function and include mock responses for service statuses. - Enhanced test coverage by simulating various service states, improving the reliability of the tests for the services endpoint. ### Expected Results - Improved accuracy of service health checks in tests, ensuring that the endpoint behaves correctly under different service conditions. - Enhanced maintainability of the test suite by clearly defining expected service responses.
This commit is contained in:
@@ -35,7 +35,8 @@ class TestGeneralRoutes:
|
|||||||
assert "T" in data["timestamp"] or "Z" in data["timestamp"]
|
assert "T" in data["timestamp"] or "Z" in data["timestamp"]
|
||||||
|
|
||||||
@patch("routes.general.SERVICES")
|
@patch("routes.general.SERVICES")
|
||||||
def test_get_services(self, mock_services):
|
@patch("routes.general.status_checker.check_all_services")
|
||||||
|
def test_get_services(self, mock_check_services, mock_services):
|
||||||
"""Test the get services endpoint"""
|
"""Test the get services endpoint"""
|
||||||
# Mock the services configuration
|
# Mock the services configuration
|
||||||
mock_services.items.return_value = [
|
mock_services.items.return_value = [
|
||||||
@@ -47,6 +48,31 @@ class TestGeneralRoutes:
|
|||||||
("immich", {"enabled": False, "url": "http://immich.local:2283"}),
|
("immich", {"enabled": False, "url": "http://immich.local:2283"}),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# Mock the health check results
|
||||||
|
mock_check_services.return_value = {
|
||||||
|
"home_assistant": {
|
||||||
|
"status": "unknown",
|
||||||
|
"response_time": None,
|
||||||
|
"error": None,
|
||||||
|
"uptime": None,
|
||||||
|
"metadata": {}
|
||||||
|
},
|
||||||
|
"frigate": {
|
||||||
|
"status": "unknown",
|
||||||
|
"response_time": None,
|
||||||
|
"error": None,
|
||||||
|
"uptime": None,
|
||||||
|
"metadata": {}
|
||||||
|
},
|
||||||
|
"immich": {
|
||||||
|
"status": "disabled",
|
||||||
|
"response_time": None,
|
||||||
|
"error": None,
|
||||||
|
"uptime": None,
|
||||||
|
"metadata": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
response = client.get("/services")
|
response = client.get("/services")
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user