Skip to content

Commit

Permalink
Add backend health route (#743)
Browse files Browse the repository at this point in the history
* Add backend health route

* remove openapi schema

* JGoat

---------

Co-authored-by: Sritan Motati <[email protected]>
  • Loading branch information
rm03 and sritanmotati authored Nov 12, 2024
1 parent 618b65c commit a916b91
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions backend/clubs/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
FavoriteCalendarAPIView,
FavoriteEventsAPIView,
FavoriteViewSet,
HealthView,
MajorViewSet,
MassInviteAPIView,
MeetingZoomAPIView,
Expand Down Expand Up @@ -176,6 +177,7 @@
WhartonApplicationStatusAPIView.as_view(),
name="wharton-applications-status",
),
path(r"health/", HealthView.as_view(), name="health"),
]

urlpatterns += router.urls
Expand Down
21 changes: 21 additions & 0 deletions backend/clubs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7565,6 +7565,27 @@ def post(self, request):
return Response({"output": output.getvalue()})


class HealthView(APIView):
def get(self, request):
"""
Health check endpoint to confirm the backend is running.
---
summary: Health Check
responses:
"200":
content:
application/json:
schema:
type: object
properties:
message:
type: string
enum: ["OK"]
---
"""
return Response({"message": "OK"}, status=status.HTTP_200_OK)


def get_initial_context_from_types(types):
"""
Generate a sample context given the specified types.
Expand Down
8 changes: 8 additions & 0 deletions backend/tests/clubs/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2923,3 +2923,11 @@ def test_club_approval_response_templates(self):
content_type="application/json",
)
self.assertEqual(resp.status_code, 403)


class HealthTestCase(TestCase):
def test_health(self):
url = reverse("health")
resp = self.client.get(url)
self.assertEqual(resp.status_code, 200)
self.assertEqual(resp.data, {"message": "OK"})

0 comments on commit a916b91

Please sign in to comment.