Skip to content

Commit

Permalink
Add health route for backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Clue88 committed Oct 27, 2024
1 parent 77bb898 commit 11aefa9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion backend/courses/urls.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from django.urls import path

from courses import views
from courses.views import CourseListSearch
from courses.views import CourseListSearch, Health


urlpatterns = [
path("health/", Health.as_view(), name="health"),
path("<slug:semester>/courses/", views.CourseList.as_view(), name="courses-list"),
path(
"<slug:semester>/search/courses/",
Expand Down
6 changes: 6 additions & 0 deletions backend/courses/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from rest_framework.exceptions import ValidationError
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.views import APIView

from courses.filters import CourseSearchFilterBackend
from courses.models import (
Expand Down Expand Up @@ -49,6 +50,11 @@
)


class Health(APIView):
def get(self, request):
return Response({"message": "OK"}, status=status.HTTP_200_OK)


class BaseCourseMixin(AutoPrefetchViewSetMixin, generics.GenericAPIView):
@staticmethod
def get_semester_field():
Expand Down
9 changes: 9 additions & 0 deletions backend/tests/courses/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.test import RequestFactory, TestCase
from django.urls import reverse
from options.models import Option
from rest_framework import status
from rest_framework.test import APIClient

from alert.models import AddDropPeriod
Expand Down Expand Up @@ -42,6 +43,14 @@ def set_semester():
AddDropPeriod(semester=TEST_SEMESTER).save()


class HealthTestCase(TestCase):
def test_health_check(self):
url = reverse("health")
response = self.client.get(url)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data, {"message": "OK"})


class CourseListTestCase(TestCase):
def setUp(self):
set_semester()
Expand Down

0 comments on commit 11aefa9

Please sign in to comment.