diff --git a/tests/unit/app/endpoints/test_config.py b/tests/unit/app/endpoints/test_config.py new file mode 100644 index 000000000..580c77db3 --- /dev/null +++ b/tests/unit/app/endpoints/test_config.py @@ -0,0 +1,46 @@ +from fastapi import HTTPException, status +from fastapi import Request +import pytest + +from app.endpoints.config import config_endpoint_handler +from models.config import Configuration +from configuration import configuration +from configuration import AppConfig + + +def test_config_endpoint_handler_configuration_not_loaded(mocker): + """Test the config endpoint handler.""" + mocker.patch( + "app.endpoints.query.configuration", + return_value=mocker.Mock(), + ) + + request = None + with pytest.raises(Exception, match="logic error: configuration is not loaded"): + config_endpoint_handler(request) + + +def test_config_endpoint_handler_configuration_loaded(mocker): + """Test the config endpoint handler.""" + config_dict = { + "name": "foo", + "service": { + "host": "localhost", + "port": 8080, + "auth_enabled": False, + "workers": 1, + "color_log": True, + "access_log": True, + }, + "llama_stack": { + "api_key": "xyzzy", + "url": "http://x.y.com:1234", + "use_as_library_client": False, + }, + } + cfg = AppConfig() + cfg.init_from_dict(config_dict) + request = None + response = config_endpoint_handler(request) + assert response is not None + assert response == cfg.configuration