Add /status route

Currently this only prints the API version.
This commit is contained in:
Alan Orth 2020-12-22 11:30:09 +02:00
parent a9d2a6d9be
commit 4b1398c67f
Signed by: alanorth
GPG Key ID: 0FB860CC9C45B1B9
3 changed files with 21 additions and 0 deletions

View File

@ -5,6 +5,7 @@ from falcon_swagger_ui import register_swaggerui_app
from .database import DatabaseManager
from .stats import get_downloads, get_views
from .util import set_statistics_scope, validate_post_parameters
from .config import VERSION
class RootResource:
@ -15,6 +16,14 @@ class RootResource:
resp.body = f.read()
class StatusResource:
def on_get(self, req, resp):
message = {"version": VERSION}
resp.status = falcon.HTTP_200
resp.media = message
class OpenAPIJSONResource:
def on_get(self, req, resp):
resp.status = falcon.HTTP_200
@ -174,6 +183,7 @@ class SingleStatisticsResource:
api = application = falcon.API()
api.add_route("/", RootResource())
api.add_route("/status", StatusResource())
# Item routes
api.add_route("/items", AllStatisticsResource())

View File

@ -9,4 +9,6 @@ DATABASE_PASS = os.environ.get("DATABASE_PASS", "dspacestatistics")
DATABASE_HOST = os.environ.get("DATABASE_HOST", "localhost")
DATABASE_PORT = os.environ.get("DATABASE_PORT", "5432")
VERSION = "1.4.0-dev"
# vim: set sw=4 ts=4 expandtab:

View File

@ -34,3 +34,12 @@ def test_get_swagger_ui(client):
assert isinstance(response.content, bytes)
assert response.status_code == 200
def test_get_status(client):
"""Test requesting the status page."""
response = client.simulate_get("/status")
assert isinstance(response.content, bytes)
assert response.status_code == 200