diff --git a/app/main.py b/app/main.py index f98e9b8..b869e44 100644 --- a/app/main.py +++ b/app/main.py @@ -9,7 +9,7 @@ from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from fastapi.openapi.docs import get_redoc_html, get_swagger_ui_html -from fastapi.responses import ORJSONResponse, RedirectResponse +from fastapi.responses import HTMLResponse, ORJSONResponse, RedirectResponse from .api import utility as util from .api.routers import attributes, query @@ -28,6 +28,21 @@ ) +@app.get("/", response_class=HTMLResponse) +def root(): + """ + Display a welcome message and a link to the API documentation. + """ + return """ + +
+Please visit the documentation to view available API endpoints.
+ + + """ + + @app.get("/favicon.ico", include_in_schema=False) async def favicon(): """ diff --git a/tests/test_attributes.py b/tests/test_attributes.py index 1583572..c8e15a9 100644 --- a/tests/test_attributes.py +++ b/tests/test_attributes.py @@ -7,6 +7,17 @@ from app.api import utility as util +def test_root(test_app, set_test_credentials): + """Given a GET request to the root endpoint, Check for 200 status and expected content.""" + + with test_app: + response = test_app.get("/") + + assert response.status_code == 200 + assert "Welcome to the Neurobagel REST API!" in response.text + assert 'documentation' in response.text + + @pytest.mark.parametrize( "valid_data_element_URI", ["nb:Diagnosis", "nb:Assessment"],