484885a1a0deda9a03da33edcf5c885f1a288f28
[vfc/gvnfm/vnflcm.git] / lcm / lcm / nf / tests / test_update_vnf.py
1 # Copyright 2019 ZTE Corporation.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #         http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 import mock
16 from django.test import TestCase
17 from rest_framework.test import APIClient
18 from rest_framework import status
19
20 from lcm.pub.utils import restcall
21 from lcm.pub.database.models import NfInstModel
22 from lcm.pub.utils.jobutil import JobUtil
23 from lcm.nf.biz.update_vnf import UpdateVnf
24
25
26 class TestNFUpdate(TestCase):
27     def setUp(self):
28         self.client = APIClient()
29         self.upd_data = {
30             "vnfInstanceName": "vnf new name",
31             "vnfInstanceDescription": "new description"
32         }
33
34     def tearDown(self):
35         pass
36
37     def test_update_vnf_not_exist(self):
38         response = self.client.patch("/api/vnflcm/v1/vnf_instances/1111",
39                                      data=self.upd_data,
40                                      format='json')
41         self.failUnlessEqual(status.HTTP_404_NOT_FOUND, response.status_code)
42
43     @mock.patch.object(restcall, 'call_req')
44     def test_update_vnf_success(self, mock_call_req):
45         instanceid = "12"
46         NfInstModel(nfinstid=instanceid,
47                     nf_name='VNF1',
48                     nf_desc="VNF DESC",
49                     vnfdid="1",
50                     netype="XGW",
51                     vendor="ZTE",
52                     vnfSoftwareVersion="V1",
53                     version="V1",
54                     package_id="2",
55                     status='INSTANTIATED').save()
56         mock_call_req.return_value = [0, {}, status.HTTP_202_ACCEPTED]
57         job_id = JobUtil.create_job('NF', 'UPDATETEST', instanceid)
58         UpdateVnf(self.upd_data, instanceid, job_id).run()
59         name = NfInstModel.objects.filter(nfinstid=instanceid).get().nf_name
60         self.failUnlessEqual("vnf new name", name)