aboutsummaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorGravatar Johannes Christ <[email protected]>2018-08-16 20:54:01 +0200
committerGravatar Johannes Christ <[email protected]>2018-08-16 20:54:01 +0200
commit9766d41be89a6889b3c99af890f362e18f57d391 (patch)
tree9aa20328d1f374a49e8363e1efa3fc5cd2634900 /api
parentSmall documentation fixes. (diff)
Add a `HealthcheckView`.
Diffstat (limited to 'api')
-rw-r--r--api/tests/test_healthcheck.py16
-rw-r--r--api/urls.py2
-rw-r--r--api/views.py27
3 files changed, 45 insertions, 0 deletions
diff --git a/api/tests/test_healthcheck.py b/api/tests/test_healthcheck.py
new file mode 100644
index 00000000..b0fd71bf
--- /dev/null
+++ b/api/tests/test_healthcheck.py
@@ -0,0 +1,16 @@
+from django_hosts.resolvers import reverse
+
+from .base import APISubdomainTestCase
+
+
+class UnauthedHealthcheckAPITests(APISubdomainTestCase):
+ def setUp(self):
+ super().setUp()
+ self.client.force_authenticate(user=None)
+
+ def test_can_access_healthcheck_view(self):
+ url = reverse('healthcheck', host='api')
+ response = self.client.get(url)
+
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(response.json(), {'status': 'ok'})
diff --git a/api/urls.py b/api/urls.py
index dfc739bb..b0e104cd 100644
--- a/api/urls.py
+++ b/api/urls.py
@@ -1,6 +1,7 @@
from django.urls import include, path
from rest_framework.routers import SimpleRouter
+from .views import HealthcheckView
from .viewsets import SnakeNameViewSet
@@ -15,4 +16,5 @@ urlpatterns = (
# from django_hosts.resolvers import reverse
# snake_name_endpoint = reverse('bot:snakename-list', host='api') # `bot/` endpoints
path('bot/', include((bot_router.urls, 'api'), namespace='bot')),
+ path('healthcheck', HealthcheckView.as_view(), name='healthcheck')
)
diff --git a/api/views.py b/api/views.py
new file mode 100644
index 00000000..dbc04b56
--- /dev/null
+++ b/api/views.py
@@ -0,0 +1,27 @@
+from rest_framework.response import Response
+from rest_framework.views import APIView
+
+
+class HealthcheckView(APIView):
+ """
+ Provides a simple view to check that the website is alive and well.
+
+ ## Routes
+ ### GET /healthcheck
+ Returns a simple JSON document showcasing whether the system is working:
+
+ >>> {
+ ... 'status': 'ok'
+ ... }
+
+ Seems to be.
+
+ ## Authentication
+ Does not require any authentication nor permissions..
+ """
+
+ authentication_classes = ()
+ permission_classes = ()
+
+ def get(self, request, format=None):
+ return Response({'status': 'ok'})