import logging
+from drf_yasg.utils import swagger_auto_schema
+from rest_framework import status
+from rest_framework.response import Response
from rest_framework.views import APIView
logger = logging.getLogger(__name__)
class HealthCheckView(APIView):
- logger.debug("Health check")
- pass
+ @swagger_auto_schema(
+ responses={
+ status.HTTP_200_OK: 'Active'})
+ def get(self, request, format=None):
+ logger.debug("Health check.")
+ return Response({"status": "active"})
response = self.client.post("/api/vnfmgr/v1/configuration", self.vnfconfig, format='json')
self.assertEqual(status.HTTP_500_INTERNAL_SERVER_ERROR, response.status_code, response.content)
self.assertEqual({'error': "Vnf(1) does not exist."}, json.loads(response.content))
+
+
+class HealthCheckViewTest(unittest.TestCase):
+ def setUp(self):
+ self.client = APIClient()
+
+ def tearDown(self):
+ pass
+
+ def test_health_check(self):
+ response = self.client.get("/api/vnfmgr/v1/health_check")
+ self.assertEqual(status.HTTP_200_OK, response.status_code, response.content)
+ resp_data = json.loads(response.content)
+ self.assertEqual({"status": "active"}, resp_data)
url(r'^api/vnfmgr/v1/configuration$', views.vnf_config, name='vnf_config'),
# health check
- url(r'^api/vnfmgr/v1/healthcheck$', HealthCheckView.as_view()),
+ url(r'^api/vnfmgr/v1/health_check$', HealthCheckView.as_view()),
]