File tree Expand file tree Collapse file tree 3 files changed +31
-1
lines changed
Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Original file line number Diff line number Diff line change 88from django .test import TestCase
99from unittest import skip
1010from django .core import mail
11+ from django .urls import reverse
1112
1213from django .contrib .auth .models import User
1314from .models import CFAUser , Event , Grant
@@ -348,6 +349,11 @@ def test_get_or_none_exists(self):
348349 def test_get_or_none_does_not_exist (self ):
349350 self .assertEqual (None , helpers .get_or_none (Event , pk = 2 ))
350351
352+ class HealthTestCase (TestCase ):
353+ def test_health (self ):
354+ resp = self .client .get ("/health/" )
355+ self .assertEqual (resp .status_code , 200 )
356+ self .assertEqual (resp .json (), {"message" : "OK" })
351357
352358class TestExportRequests (TestCase ):
353359 def setUp (self ):
Original file line number Diff line number Diff line change 1212 # re_path(r'^(\d+)/download/$', views.event_download, name='event-download'),
1313 re_path (r'^funders/(\d+)/edit/$' , views .funder_edit , name = 'funder-edit' ),
1414 re_path (r'^export-requests/$' , views .export_requests , name = 'export-requests' ),
15+ re_path (r'^health/' , views .HealthView .as_view (), name = 'health' ),
1516]
Original file line number Diff line number Diff line change 33from datetime import timedelta
44import json
55import re
6+ from http import HTTPStatus
7+ from django .http import JsonResponse
8+ from django .views .generic import View
69
710import smtplib
811from django .contrib .auth .views import LoginView
@@ -477,6 +480,26 @@ def funder_edit(request, user_id):
477480 else :
478481 return HttpResponseNotAllowed (["GET" ])
479482
483+ class HealthView (View ):
484+ def get (self , request ):
485+ """
486+ Health check endpoint to confirm the backend is running.
487+ ---
488+ summary: Health Check
489+ responses:
490+ "200":
491+ content:
492+ application/json:
493+ schema:
494+ type: object
495+ properties:
496+ message:
497+ type: string
498+ enum: ["OK"]
499+ ---
500+ """
501+ return JsonResponse ({"message" : "OK" }, status = HTTPStatus .OK )
502+
480503@admin_only
481504@require_http_methods (["GET" ])
482505def export_requests (request ):
@@ -555,4 +578,4 @@ def export_requests(request):
555578
556579 response = HttpResponse (output .getvalue (), content_type = 'text/csv' )
557580 response ['Content-Disposition' ] = 'attachment; filename="funding_requests.csv"'
558- return response
581+ return response
You can’t perform that action at this time.
0 commit comments