From 53c7cea6903d39b8e99644b2242b8704fa1ec915 Mon Sep 17 00:00:00 2001 From: Adam Outler Date: Sat, 31 Jan 2026 15:29:51 +0000 Subject: [PATCH 1/4] Add api redirect from / to /docs --- server/api_server/api_server_start.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/server/api_server/api_server_start.py b/server/api_server/api_server_start.py index de68c90d..daf9c274 100755 --- a/server/api_server/api_server_start.py +++ b/server/api_server/api_server_start.py @@ -4,7 +4,7 @@ import os # flake8: noqa: E402 -from flask import Flask, request, jsonify, Response +from flask import Flask, redirect, request, jsonify, url_for, Response from models.device_instance import DeviceInstance # noqa: E402 from flask_cors import CORS from werkzeug.exceptions import HTTPException @@ -1165,6 +1165,11 @@ def api_docs(): return send_from_directory(openapi_dir, 'swagger.html') +@app.route('/') +def index_redirect(): + """Redirect root to API documentation.""" + return redirect(url_for('api_docs')) + # -------------------------- # DB query # -------------------------- From d404c4584354782f398196161ae7dc209b04967f Mon Sep 17 00:00:00 2001 From: Adam Outler Date: Sat, 31 Jan 2026 15:30:01 +0000 Subject: [PATCH 2/4] Add basic unit tests --- test/api_endpoints/test_docs.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 test/api_endpoints/test_docs.py diff --git a/test/api_endpoints/test_docs.py b/test/api_endpoints/test_docs.py new file mode 100644 index 00000000..b8b84a80 --- /dev/null +++ b/test/api_endpoints/test_docs.py @@ -0,0 +1,24 @@ +# tests/test_root_redirect.py + + +from api_server import api_server_start + + +def test_index_redirect_logic(): + """Test the redirect function logic directly.""" + with api_server_start.app.test_request_context(): + response = api_server_start.index_redirect() + # In Flask, a redirect return object is a Response + assert response.status_code == 302 + assert response.headers['Location'] == '/docs' + + +def test_api_docs_logic(): + """Test that api_docs attempts to serve the correct file.""" + with api_server_start.app.test_request_context(): + response = api_server_start.api_docs() + assert response.status_code == 200 + assert response.mimetype == 'text/html' + # Manually join the chunks from the generator + data = b"".join(response.response) + assert b'' in data or b'' in data From 53962bc38b3809c08173031f62895116fe9e01b4 Mon Sep 17 00:00:00 2001 From: Adam Outler Date: Sat, 31 Jan 2026 10:41:58 -0500 Subject: [PATCH 3/4] Update test/api_endpoints/test_docs.py Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- test/api_endpoints/test_docs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/api_endpoints/test_docs.py b/test/api_endpoints/test_docs.py index b8b84a80..6c6bbabc 100644 --- a/test/api_endpoints/test_docs.py +++ b/test/api_endpoints/test_docs.py @@ -1,4 +1,4 @@ -# tests/test_root_redirect.py +# test/api_endpoints/test_docs.py - Tests for root redirect and API docs endpoints from api_server import api_server_start From 77fd017d908720c21cd1670d2df7cb5f67408e49 Mon Sep 17 00:00:00 2001 From: Adam Outler Date: Sat, 31 Jan 2026 16:52:30 +0000 Subject: [PATCH 4/4] Coderabbit requested changes --- test/api_endpoints/test_docs.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/test/api_endpoints/test_docs.py b/test/api_endpoints/test_docs.py index 6c6bbabc..bc12cecf 100644 --- a/test/api_endpoints/test_docs.py +++ b/test/api_endpoints/test_docs.py @@ -6,19 +6,18 @@ from api_server import api_server_start def test_index_redirect_logic(): """Test the redirect function logic directly.""" - with api_server_start.app.test_request_context(): - response = api_server_start.index_redirect() - # In Flask, a redirect return object is a Response + with api_server_start.app.test_client() as client: + response = client.get("/", follow_redirects=False) assert response.status_code == 302 - assert response.headers['Location'] == '/docs' + assert response.location == '/docs' def test_api_docs_logic(): """Test that api_docs attempts to serve the correct file.""" - with api_server_start.app.test_request_context(): - response = api_server_start.api_docs() + with api_server_start.app.test_client() as client: + response = client.get("/docs") assert response.status_code == 200 - assert response.mimetype == 'text/html' - # Manually join the chunks from the generator - data = b"".join(response.response) - assert b'' in data or b'' in data + assert response.mimetype == "text/html" + response.direct_passthrough = False + data = response.get_data() + assert b"" in data or b"" in data