Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
"/": {
Expand Down Expand Up @@ -268,7 +268,10 @@
]
},
"503": {
"description": "Configuration can not be loaded"
"description": "Service Unavailable",
"detail": {
"response": "Configuration is no loaded"
}
}
}
}
Expand Down
12 changes: 10 additions & 2 deletions src/app/endpoints/config.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"])
Expand Down Expand Up @@ -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
8 changes: 6 additions & 2 deletions tests/unit/app/endpoints/test_config.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import pytest

from fastapi import HTTPException, status
from app.endpoints.config import config_endpoint_handler
from configuration import AppConfig


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):
Expand Down