mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2026-04-12 13:11:47 -07:00
Merge pull request #1477 from adamoutler/redirect-to-docs
Redirect from / to /docs
This commit is contained in:
@@ -4,7 +4,7 @@ import os
|
|||||||
|
|
||||||
# flake8: noqa: E402
|
# 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 models.device_instance import DeviceInstance # noqa: E402
|
||||||
from flask_cors import CORS
|
from flask_cors import CORS
|
||||||
from werkzeug.exceptions import HTTPException
|
from werkzeug.exceptions import HTTPException
|
||||||
@@ -1165,6 +1165,11 @@ def api_docs():
|
|||||||
return send_from_directory(openapi_dir, 'swagger.html')
|
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
|
# DB query
|
||||||
# --------------------------
|
# --------------------------
|
||||||
|
|||||||
23
test/api_endpoints/test_docs.py
Normal file
23
test/api_endpoints/test_docs.py
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# test/api_endpoints/test_docs.py - Tests for root redirect and API docs endpoints
|
||||||
|
|
||||||
|
|
||||||
|
from api_server import api_server_start
|
||||||
|
|
||||||
|
|
||||||
|
def test_index_redirect_logic():
|
||||||
|
"""Test the redirect function logic directly."""
|
||||||
|
with api_server_start.app.test_client() as client:
|
||||||
|
response = client.get("/", follow_redirects=False)
|
||||||
|
assert response.status_code == 302
|
||||||
|
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_client() as client:
|
||||||
|
response = client.get("/docs")
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert response.mimetype == "text/html"
|
||||||
|
response.direct_passthrough = False
|
||||||
|
data = response.get_data()
|
||||||
|
assert b"<!DOCTYPE html>" in data or b"<html>" in data
|
||||||
Reference in New Issue
Block a user