From 7fa17624b50db1d5e322b976abf3af3e39806f9b Mon Sep 17 00:00:00 2001 From: GSRN Date: Thu, 18 Sep 2025 13:18:32 +0200 Subject: [PATCH] test: Update service health check tests to include mock responses ### 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. --- .../tests/test_general_routes.py | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/services/service-adapters/tests/test_general_routes.py b/services/service-adapters/tests/test_general_routes.py index d47aff7..e221470 100644 --- a/services/service-adapters/tests/test_general_routes.py +++ b/services/service-adapters/tests/test_general_routes.py @@ -35,7 +35,8 @@ class TestGeneralRoutes: assert "T" in data["timestamp"] or "Z" in data["timestamp"] @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""" # Mock the services configuration mock_services.items.return_value = [ @@ -47,6 +48,31 @@ class TestGeneralRoutes: ("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") assert response.status_code == 200