Skip to content

Commit e8e13e5

Browse files
committed
added healthcheck
1 parent 4a26ed2 commit e8e13e5

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

backend/penndata/views.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from django.shortcuts import get_object_or_404
88
from django.utils import timezone
99
from requests.exceptions import ConnectionError
10-
from rest_framework import generics
10+
from rest_framework import generics, status
1111
from rest_framework.permissions import AllowAny, IsAuthenticated
1212
from rest_framework.response import Response
1313
from rest_framework.views import APIView
@@ -31,6 +31,11 @@
3131
from pennmobile.analytics import LabsAnalytics
3232

3333

34+
class Health(APIView):
35+
def get(self, request):
36+
return Response({"message": "OK"}, status=status.HTTP_200_OK)
37+
38+
3439
class News(APIView):
3540
"""
3641
GET: Get's news article from the DP

backend/pennmobile/urls.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from django.views.generic import TemplateView
66
from rest_framework.schemas import get_schema_view
77

8+
from penndata.views import Health
9+
810

911
urlpatterns = [
1012
path("gsr/", include("gsr_booking.urls")),
@@ -56,6 +58,7 @@ def universal_identifier_link(request):
5658
urlpatterns = [
5759
path("api/", include(urlpatterns)),
5860
path("", include((urlpatterns, "apex"))),
61+
path("health/", Health.as_view(), name="health"),
5962
path(
6063
".well-known/apple-app-site-association", universal_identifier_link, name="universal-links"
6164
),

backend/tests/penndata/test_views.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from django.test import TestCase
88
from django.urls import reverse
99
from django.utils import timezone
10+
from rest_framework import status
1011
from rest_framework.test import APIClient
1112

1213
from dining.models import Venue
@@ -36,6 +37,14 @@ def fakeFitnessGet(url, *args, **kwargs):
3637
User = get_user_model()
3738

3839

40+
class HealthTestCase(TestCase):
41+
def test_health_check(self):
42+
url = reverse("health")
43+
response = self.client.get(url)
44+
self.assertEqual(response.status_code, status.HTTP_200_OK)
45+
self.assertEqual(response.data, {"message": "OK"})
46+
47+
3948
class TestNews(TestCase):
4049
def test_response(self):
4150
response = self.client.get(reverse("news"))

0 commit comments

Comments
 (0)