From 37c61811e8ec979ff0ab9c909a53e2b89bb7bb3f Mon Sep 17 00:00:00 2001 From: Pavel Tisnovsky Date: Sun, 6 Jul 2025 12:00:38 +0200 Subject: [PATCH 1/3] Configuration loading check in /config endpoint --- src/app/endpoints/config.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/app/endpoints/config.py b/src/app/endpoints/config.py index 07e79da9..8cedc74d 100644 --- a/src/app/endpoints/config.py +++ b/src/app/endpoints/config.py @@ -1,4 +1,4 @@ -"""Handler for REST API call to configuration.""" +"""Handler for REST API call to retrieve service configuration.""" import logging from typing import Any @@ -7,6 +7,7 @@ from models.config import Configuration from configuration import configuration +from utils.endpoints import check_configuration_loaded logger = logging.getLogger(__name__) router = APIRouter(tags=["config"]) @@ -46,11 +47,18 @@ {"name": "server3", "provider_id": "provider3", "url": "http://url.com:3"}, ], }, - 503: {"description": "Configuration can not be loaded"}, + 503: { + "detail": { + "response": "Configuration is no loaded", + } + }, } @router.get("/config", responses=get_config_responses) def config_endpoint_handler(_request: Request) -> Configuration: """Handle requests to the /config endpoint.""" + # ensure that configuration is loaded + check_configuration_loaded(configuration) + return configuration.configuration From f3e00c7a2d0c8a64f79824ee568e88ad4caffd85 Mon Sep 17 00:00:00 2001 From: Pavel Tisnovsky Date: Sun, 6 Jul 2025 12:02:33 +0200 Subject: [PATCH 2/3] Updated unit tests accordingly --- tests/unit/app/endpoints/test_config.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/unit/app/endpoints/test_config.py b/tests/unit/app/endpoints/test_config.py index 38296ce1..4ca1ad5d 100644 --- a/tests/unit/app/endpoints/test_config.py +++ b/tests/unit/app/endpoints/test_config.py @@ -1,5 +1,6 @@ import pytest +from fastapi import HTTPException, status from app.endpoints.config import config_endpoint_handler from configuration import AppConfig @@ -7,13 +8,16 @@ def test_config_endpoint_handler_configuration_not_loaded(mocker): """Test the config endpoint handler.""" mocker.patch( - "app.endpoints.query.configuration", + "app.endpoints.config.configuration", return_value=mocker.Mock(), ) + mocker.patch("app.endpoints.config.configuration", None) request = None - with pytest.raises(Exception, match="logic error: configuration is not loaded"): + with pytest.raises(HTTPException) as e: config_endpoint_handler(request) + assert e.status_code == status.HTTP_500_INTERNAL_SERVER_ERROR + assert e.detail["response"] == "Configuration is not loaded" def test_config_endpoint_handler_configuration_loaded(mocker): From 25cab0d7337cfd7e771cc19f43abb332eec75e09 Mon Sep 17 00:00:00 2001 From: Pavel Tisnovsky Date: Sun, 6 Jul 2025 12:03:40 +0200 Subject: [PATCH 3/3] Updated OpenAPI schema --- docs/openapi.json | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/openapi.json b/docs/openapi.json index 4611654c..9c4d3c87 100644 --- a/docs/openapi.json +++ b/docs/openapi.json @@ -7,7 +7,7 @@ "name": "Apache 2.0", "url": "https://www.apache.org/licenses/LICENSE-2.0.html" }, - "version": "0.0.1" + "version": "0.1.0" }, "paths": { "/": { @@ -268,7 +268,10 @@ ] }, "503": { - "description": "Configuration can not be loaded" + "description": "Service Unavailable", + "detail": { + "response": "Configuration is no loaded" + } } } }