diff --git a/geoapi/routes/__init__.py b/geoapi/routes/__init__.py index 60449360..d1d64c43 100644 --- a/geoapi/routes/__init__.py +++ b/geoapi/routes/__init__.py @@ -1,5 +1,6 @@ from flask_restx import Api from .projects import api as projects +from .status import api as status from .streetview import api as streetview from .notifications import api as notifications from .public_projects import api as public_projects @@ -26,4 +27,5 @@ api.add_namespace(projects) api.add_namespace(public_projects) api.add_namespace(notifications) +api.add_namespace(status) api.add_namespace(streetview) diff --git a/geoapi/routes/status.py b/geoapi/routes/status.py new file mode 100644 index 00000000..88d8aa50 --- /dev/null +++ b/geoapi/routes/status.py @@ -0,0 +1,23 @@ +from flask_restx import Resource, Namespace, fields +import time +from geoapi.log import logging +from geoapi.utils.decorators import jwt_decoder, not_anonymous + +logger = logging.getLogger(__name__) + +api = Namespace('status', decorators=[jwt_decoder]) + +status_response = api.model('StatusResponse', { + "status": fields.String(), +}) + + +@api.route("/") +class Status(Resource): + @api.doc(id="get", + description='Get status') + @api.marshal_with(status_response) + @not_anonymous + def get(self): + time.sleep(1) + return {"status": "OK"} diff --git a/geoapi/tests/api_tests/test_status_routes.py b/geoapi/tests/api_tests/test_status_routes.py new file mode 100644 index 00000000..580815e0 --- /dev/null +++ b/geoapi/tests/api_tests/test_status_routes.py @@ -0,0 +1,11 @@ +def test_get_status_unauthorized_guest(test_client, projects_fixture): + resp = test_client.get('/status/') + assert resp.status_code == 403 + + +def test_get_status(test_client, user1): + resp = test_client.get('/status/', + headers={'x-jwt-assertion-test': user1.jwt}) + data = resp.get_json() + assert resp.status_code == 200 + assert data == {'status': 'OK'}