Notification stuffs.
[vfc/gvnfm/vnflcm.git] / lcm / lcm / nf / tests / test_operate_vnf.py
index 625d40a..3ebc90a 100644 (file)
 # limitations under the License.\r
 \r
 import json\r
+import uuid\r
 \r
 import mock\r
 from django.test import TestCase, Client\r
 from rest_framework import status\r
 \r
 from lcm.nf.biz.operate_vnf import OperateVnf\r
-from lcm.pub.database.models import NfInstModel, JobStatusModel, VmInstModel\r
+from lcm.pub.database.models import NfInstModel, JobStatusModel, VmInstModel, SubscriptionModel\r
 from lcm.pub.utils import restcall\r
 from lcm.pub.utils.jobutil import JobUtil\r
+from lcm.pub.utils.notificationsutil import NotificationsUtil\r
 from lcm.pub.utils.timeutil import now_time\r
 from lcm.pub.vimapi import api\r
 \r
@@ -68,7 +70,8 @@ class TestNFOperate(TestCase):
 \r
     @mock.patch.object(restcall, 'call_req')\r
     @mock.patch.object(api, 'call')\r
-    def test_operate_vnf_success_start(self, mock_call, mock_call_req):\r
+    @mock.patch.object(NotificationsUtil, 'post_notification')\r
+    def test_operate_vnf_success_start(self, mock_post_notification, mock_call, mock_call_req):\r
         NfInstModel.objects.create(nfinstid='1111',\r
                                    nf_name='2222',\r
                                    vnfminstid='1',\r
@@ -93,11 +96,39 @@ class TestNFOperate(TestCase):
                                    vmname="test_01",\r
                                    is_predefined=1,\r
                                    operationalstate=1)\r
+\r
+        SubscriptionModel.objects.create(\r
+            subscription_id=str(uuid.uuid4()),\r
+            callback_uri='api/gvnfmdriver/v1/vnfs/lifecyclechangesnotification',\r
+            auth_info=json.JSONEncoder().encode({\r
+                'authType': ['BASIC'],\r
+                'paramsBasic': {\r
+                    'userName': 'username',\r
+                    'password': 'password'\r
+                }\r
+            }),\r
+            notification_types=str([\r
+                'VnfLcmOperationOccurrenceNotification',\r
+                'VnfIdentifierCreationNotification',\r
+                'VnfIdentifierDeletionNotification'\r
+            ]),\r
+            operation_types=str(['OPERATE']),\r
+            operation_states=str(['COMPLETED']),\r
+            vnf_instance_filter=json.JSONEncoder().encode({\r
+                'vnfdIds': [],\r
+                'vnfProductsFromProviders': [],\r
+                'vnfInstanceIds': ['1111'],\r
+                'vnfInstanceNames': [],\r
+            })\r
+        )\r
+\r
         t1_apply_grant_result = [0, json.JSONEncoder().encode(''), '200']\r
-        t2_lcm_notify_result = [0, json.JSONEncoder().encode(''), '200']\r
+        t2_lcm_notify_result = [0, json.JSONEncoder().encode(''), '200']\r
         t3_action_vm_start_result = [0, json.JSONEncoder().encode(''), '202']\r
-        mock_call_req.side_effect = [t1_apply_grant_result, t2_lcm_notify_result, t3_action_vm_start_result]\r
+        # mock_call_req.side_effect = [t1_apply_grant_result, t2_lcm_notify_result, t3_action_vm_start_result]\r
+        mock_call_req.side_effect = [t1_apply_grant_result, t3_action_vm_start_result]\r
         mock_call.return_value = None\r
+        mock_post_notification.return_value = None\r
         req_data = {\r
             "changeStateTo": "STARTED"\r
         }\r
@@ -111,7 +142,8 @@ class TestNFOperate(TestCase):
 \r
     @mock.patch.object(restcall, 'call_req')\r
     @mock.patch.object(api, 'call')\r
-    def test_operate_vnf_success_stop(self, mock_call, mock_call_req):\r
+    @mock.patch.object(NotificationsUtil, 'post_notification')\r
+    def test_operate_vnf_success_stop(self, mock_post_notification, mock_call, mock_call_req):\r
         NfInstModel.objects.create(nfinstid='1111',\r
                                    nf_name='2222',\r
                                    vnfminstid='1',\r
@@ -136,11 +168,39 @@ class TestNFOperate(TestCase):
                                    vmname="test_01",\r
                                    is_predefined=1,\r
                                    operationalstate=1)\r
+\r
+        SubscriptionModel.objects.create(\r
+            subscription_id=str(uuid.uuid4()),\r
+            callback_uri='api/gvnfmdriver/v1/vnfs/lifecyclechangesnotification',\r
+            auth_info=json.JSONEncoder().encode({\r
+                'authType': ['BASIC'],\r
+                'paramsBasic': {\r
+                    'userName': 'username',\r
+                    'password': 'password'\r
+                }\r
+            }),\r
+            notification_types=str([\r
+                'VnfLcmOperationOccurrenceNotification',\r
+                'VnfIdentifierCreationNotification',\r
+                'VnfIdentifierDeletionNotification'\r
+            ]),\r
+            operation_types=str(['OPERATE']),\r
+            operation_states=str(['COMPLETED']),\r
+            vnf_instance_filter=json.JSONEncoder().encode({\r
+                'vnfdIds': [],\r
+                'vnfProductsFromProviders': [],\r
+                'vnfInstanceIds': ['1111'],\r
+                'vnfInstanceNames': [],\r
+            })\r
+        )\r
+\r
         t1_apply_grant_result = [0, json.JSONEncoder().encode(''), '200']\r
-        t2_lcm_notify_result = [0, json.JSONEncoder().encode(''), '200']\r
+        t2_lcm_notify_result = [0, json.JSONEncoder().encode(''), '200']\r
         t3_action_vm_stop_result = [0, json.JSONEncoder().encode(''), '202']\r
-        mock_call_req.side_effect = [t1_apply_grant_result, t2_lcm_notify_result, t3_action_vm_stop_result]\r
+        # mock_call_req.side_effect = [t1_apply_grant_result, t2_lcm_notify_result, t3_action_vm_stop_result]\r
+        mock_call_req.side_effect = [t1_apply_grant_result, t3_action_vm_stop_result]\r
         mock_call.return_value = None\r
+        mock_post_notification.return_value = None\r
         req_data = {\r
             "changeStateTo": "STOPPED"\r
         }\r