Ns descriptor related stuffs. 49/61949/1
authorlaili <lai.li@zte.com.cn>
Thu, 23 Aug 2018 03:28:27 +0000 (11:28 +0800)
committerlaili <lai.li@zte.com.cn>
Thu, 23 Aug 2018 03:28:42 +0000 (11:28 +0800)
Add tests for creation of pnfd.
Modify names.

Change-Id: I915f561f895b9d5a033b12ba3f5dcdc350812580
Issue-ID: VFC-1037
Signed-off-by: laili <lai.li@zte.com.cn>
catalog/packages/biz/nspackage.py [moved from catalog/packages/biz/ns_package.py with 100% similarity]
catalog/packages/tests/test_pnf_descriptor.py [new file with mode: 0644]
catalog/packages/views/catalog_views.py

diff --git a/catalog/packages/tests/test_pnf_descriptor.py b/catalog/packages/tests/test_pnf_descriptor.py
new file mode 100644 (file)
index 0000000..2761d5d
--- /dev/null
@@ -0,0 +1,80 @@
+# Copyright 2017 ZTE Corporation.
+#
+# 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 os
+
+from django.test import TestCase
+from rest_framework import status
+from rest_framework.test import APIClient
+
+
+class TestPnfDescriptor(TestCase):
+    def setUp(self):
+        self.client = APIClient()
+
+    def tearDown(self):
+        pass
+
+    def test_pnfd_create_normal(self):
+        reqest_data = {
+            'userDefinedData': {
+                'key1': 'value1',
+                'key2': 'value2',
+                'key3': 'value3',
+            }
+        }
+        expected_reponse_data = {
+            'pnfdOnboardingState': 'CREATED',
+            'pnfdUsageState': 'NOT_IN_USE',
+            'userDefinedData': {
+                'key1': 'value1',
+                'key2': 'value2',
+                'key3': 'value3',
+            },
+            '_links': None
+        }
+        response = self.client.post(
+            '/api/nsd/v1/pnf_descriptors',
+            data=reqest_data,
+            format='json'
+        )
+        response.data.pop('id')
+        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
+        self.assertEqual(expected_reponse_data, response.data)
+
+    def test_query_multiple_pnfds_normal(self):
+        pass
+
+    def test_query_single_pnfd_normal(self):
+        pass
+
+    def test_delete_single_pnfd_normal(self):
+        pass
+
+    def test_pnfd_content_upload_normal(self):
+        with open('pnfd_content.txt', 'wb') as fp:
+            fp.write('test')
+
+        with open('pnfd_content.txt', 'rb') as fp:
+            resp = self.client.put(
+                "/api/nsd/v1/pnf_descriptors/22/pnfd_content",
+                {'file': fp},
+            )
+        self.assertEqual(resp.status_code, status.HTTP_204_NO_CONTENT)
+        self.assertEqual({}, resp.data)
+
+        os.remove('pnfd_content.txt')
+
+    def test_pnfd_content_upload_failure(self):
+        pass
index b735cb5..157af9f 100644 (file)
@@ -20,8 +20,7 @@ from drf_yasg.utils import no_body, swagger_auto_schema
 from rest_framework import status
 from rest_framework.decorators import api_view
 from rest_framework.response import Response
-
-from catalog.packages.biz import vnfpackage, ns_package
+from catalog.packages.biz import vnfpackage, nspackage
 from catalog.packages.serializers.catalog_serializers import InternalErrorRequestSerializer
 from catalog.packages.serializers.catalog_serializers import NfPackageDistributeRequestSerializer
 from catalog.packages.serializers.catalog_serializers import NfPackageSerializer
@@ -60,7 +59,7 @@ def nspackages_rc(request, *args, **kwargs):
 
     if request.method == 'GET':
         # Gets ns package list
-        ret = ns_package.ns_get_csars()
+        ret = nspackage.ns_get_csars()
         normal_status = status.HTTP_200_OK
 
         if ret[0] == 0:
@@ -78,7 +77,7 @@ def nspackages_rc(request, *args, **kwargs):
 
         csar_id = ignore_case_get(request.data, "csarId")
         logger.debug("csar_id is %s", csar_id)
-        ret = ns_package.ns_on_distribute(csar_id)
+        ret = nspackage.ns_on_distribute(csar_id)
         normal_status = status.HTTP_202_ACCEPTED
 
     logger.debug("Leave %s, Return value is %s", fun_name(), ret)
@@ -190,7 +189,7 @@ def ns_rd_csar(request, *args, **kwargs):
                 fun_name(), request.method, csar_id)
     ret, normal_status, response_serializer, validation_error = None, None, None, None
     if request.method == 'GET':
-        ret = ns_package.ns_get_csar(csar_id)
+        ret = nspackage.ns_get_csar(csar_id)
         normal_status = status.HTTP_200_OK
         if ret[0] == 0:
             response_serializer = NsPackageSerializer(data=ret[1])
@@ -198,7 +197,7 @@ def ns_rd_csar(request, *args, **kwargs):
             if validation_error:
                 return validation_error
     elif request.method == 'DELETE':
-        ret = ns_package.ns_delete_csar(csar_id)
+        ret = nspackage.ns_delete_csar(csar_id)
         normal_status = status.HTTP_200_OK
     logger.info("Leave %s, Return value is %s", fun_name(), ret)
     if ret[0] != 0:
@@ -291,7 +290,7 @@ def ns_model_parser(request, *args, **kwargs):
         fun_name(),
         csar_id,
         inputs)
-    ret = ns_package.parse_nsd(csar_id, inputs)
+    ret = nspackage.parse_nsd(csar_id, inputs)
     logger.info("Leave %s, Return value is %s", fun_name(), ret)
     if ret[0] != 0:
         return Response(