From 9eaf2a2d6cbe527f8ec5b9469986561116742d35 Mon Sep 17 00:00:00 2001 From: fujinhua Date: Wed, 3 Apr 2019 11:29:42 +0800 Subject: Fix health check api Change-Id: I63f9f4e25c6195418516708db3235b3c7a56443c Issue-ID: VFC-1306 Signed-off-by: fujinhua --- res/res/resources/health_check_views.py | 11 +++++++++-- res/res/resources/tests.py | 15 +++++++++++++++ res/res/resources/urls.py | 2 +- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/res/res/resources/health_check_views.py b/res/res/resources/health_check_views.py index 9df01f2..cc1a379 100644 --- a/res/res/resources/health_check_views.py +++ b/res/res/resources/health_check_views.py @@ -14,11 +14,18 @@ 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"}) diff --git a/res/res/resources/tests.py b/res/res/resources/tests.py index 8d05bf5..7534537 100644 --- a/res/res/resources/tests.py +++ b/res/res/resources/tests.py @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +import json from django.test import TestCase from rest_framework import status @@ -220,3 +221,17 @@ class ResourceTest(TestCase): response = self.client.get("/api/vnfres/v1/%s/volumes" % self.nf_inst_id) self.assertEqual(self.volumes_data, response.data) self.failUnlessEqual(status.HTTP_200_OK, response.status_code) + + +class HealthCheckViewTest(TestCase): + def setUp(self): + self.client = APIClient() + + def tearDown(self): + pass + + def test_health_check(self): + response = self.client.get("/api/vnfres/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) diff --git a/res/res/resources/urls.py b/res/res/resources/urls.py index d92db1d..41c9d08 100644 --- a/res/res/resources/urls.py +++ b/res/res/resources/urls.py @@ -28,5 +28,5 @@ urlpatterns = [ url(r'^api/vnfres/v1/(?P[0-9a-zA-Z\-\_]+)/volumes$', views.getVolumes.as_view(), name='get_volumes'), # health check - url(r'^api/vnfres/v1/healthcheck$', HealthCheckView.as_view()), + url(r'^api/vnfres/v1/health_check$', HealthCheckView.as_view()), ] -- cgit 1.2.3-korg