fix health check of catalog 29/84229/3
authoryangyan <yangyanyj@chinamobile.com>
Thu, 4 Apr 2019 10:26:13 +0000 (18:26 +0800)
committerYan Yang <yangyanyj@chinamobile.com>
Thu, 4 Apr 2019 11:28:18 +0000 (11:28 +0000)
Change-Id: I5caf3cc74035a4d27ccebbc90eb7a28834558db2
Issue-ID: VFC-1329
Signed-off-by: yangyan <yangyanyj@chinamobile.com>
catalog/packages/tests/test_health_check.py [new file with mode: 0644]
catalog/packages/urls.py
catalog/packages/views/health_check_views.py

diff --git a/catalog/packages/tests/test_health_check.py b/catalog/packages/tests/test_health_check.py
new file mode 100644 (file)
index 0000000..8c06fc9
--- /dev/null
@@ -0,0 +1,32 @@
+# Copyright (c) 2019, CMCC Technologies Co., Ltd.
+
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+
+# http://www.apache.org/licenses/LICENSE-2.0
+
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# 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, Client
+from rest_framework import status
+
+
+class TestHealthCheck(TestCase):
+    def setUp(self):
+        self.client = Client()
+
+    def tearDown(self):
+        pass
+
+    def test_health_check(self):
+        response = self.client.get("/api/vnfpkgm/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)
index f653b55..1627381 100755 (executable)
@@ -69,5 +69,5 @@ urlpatterns = [
     # url(r'^api/vnfpkgm/v1/subscriptions/(?P<subscriptionId>[0-9a-zA-Z\-\_]+)$', vnfpkg_subscription.as_view(), name='subscription_rd'),
 
     # health check
-    url(r'^api/vnfpkgm/v1/healthcheck$', HealthCheckView.as_view()),
+    url(r'^api/vnfpkgm/v1/health_check$', HealthCheckView.as_view()),
 ]
index 9df01f2..cc1a379 100644 (file)
 
 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"})