Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add backend health route #743

Merged
merged 4 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"})
Loading