Ns descriptor related stuffs. 75/62275/2
authorlaili <lai.li@zte.com.cn>
Fri, 24 Aug 2018 07:57:40 +0000 (15:57 +0800)
committerlaili <lai.li@zte.com.cn>
Fri, 24 Aug 2018 08:13:33 +0000 (16:13 +0800)
Modify test pnfd.

Change-Id: Iaa6a9a2b4bbfdbd203e5289659efe9fa8495e228
Issue-ID: VFC-1037
Signed-off-by: laili <lai.li@zte.com.cn>
catalog/packages/tests/test_pnf_descriptor.py

index 2761d5d..e5aa8d1 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 2017 ZTE Corporation.
+# Copyright 2018 ZTE Corporation.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+
+import json
 import os
 
 from django.test import TestCase
 from rest_framework import status
 from rest_framework.test import APIClient
+from catalog.pub.database.models import PnfPackageModel
 
 
 class TestPnfDescriptor(TestCase):
     def setUp(self):
         self.client = APIClient()
+        self.user_defined_data = {
+            'key1': 'value1',
+            'key2': 'value2',
+            'key3': 'value3',
+        }
 
     def tearDown(self):
         pass
 
     def test_pnfd_create_normal(self):
-        reqest_data = {
-            'userDefinedData': {
-                'key1': 'value1',
-                'key2': 'value2',
-                'key3': 'value3',
-            }
-        }
+        request_data = {'userDefinedData': self.user_defined_data}
         expected_reponse_data = {
             'pnfdOnboardingState': 'CREATED',
             'pnfdUsageState': 'NOT_IN_USE',
-            'userDefinedData': {
-                'key1': 'value1',
-                'key2': 'value2',
-                'key3': 'value3',
-            },
+            'userDefinedData': self.user_defined_data,
             '_links': None
         }
         response = self.client.post(
             '/api/nsd/v1/pnf_descriptors',
-            data=reqest_data,
+            data=request_data,
             format='json'
         )
         response.data.pop('id')
@@ -63,6 +61,12 @@ class TestPnfDescriptor(TestCase):
         pass
 
     def test_pnfd_content_upload_normal(self):
+        user_defined_data_json = json.JSONEncoder().encode(self.user_defined_data)
+        PnfPackageModel(
+            pnfPackageId='22',
+            usageState='NOT_IN_USE',
+            userDefinedData=user_defined_data_json,
+        ).save()
         with open('pnfd_content.txt', 'wb') as fp:
             fp.write('test')