Modify testcase of delete vnf instance
[vfc/gvnfm/vnflcm.git] / lcm / lcm / nf / vnfs / tests / test_vnf_cancel.py
1 # Copyright 2017 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 from django.test import TestCase, Client
15 from rest_framework import status
16
17 from lcm.pub.database.models import NfInstModel
18 from lcm.pub.utils.timeutil import now_time
19
20
21 class TestNFTerminate(TestCase):
22     def setUp(self):
23         self.client = Client()
24
25     def tearDown(self):
26         pass
27
28     def test_delete_vnf_identifier(self):
29         NfInstModel.objects.create(nfinstid='1111', mnfinstid='1111', nf_name='2222',
30                                    package_id='todo', vnfm_inst_id='todo', version='', vendor='',
31                                    producttype='', netype='', vnfd_model='',
32                                    instantiationState='VNF_INSTANTIATED', nf_desc='', vnfdid='',
33                                    vnfSoftwareVersion='', vnfConfigurableProperties='todo',
34                                    localizationLanguage='EN_US', create_time=now_time())
35         response = self.client.delete("/openoapi/vnflcm/v1/vnf_instances/1111")
36         self.failUnlessEqual(status.HTTP_204_NO_CONTENT, response.status_code)
37         self.assertEqual(None, response.data)
38
39     def test_delete_vnf_identifier_when_vnf_not_exist(self):
40         response = self.client.delete("/openoapi/vnflcm/v1/vnf_instances/1111")
41         self.failUnlessEqual(status.HTTP_500_INTERNAL_SERVER_ERROR, response.status_code)
42         self.assertEqual("VnfInst(1111) does not exist", response.data["error"])
43
44     def test_delete_vnf_identifier_when_instantiationState_check_failed(self):
45         NfInstModel.objects.create(nfinstid='1111', mnfinstid='1111', nf_name='2222',
46                                    package_id='todo', vnfm_inst_id='todo', version='', vendor='',
47                                    producttype='', netype='', vnfd_model='',
48                                    instantiationState='NOT_INSTANTIATED', nf_desc='', vnfdid='',
49                                    vnfSoftwareVersion='', vnfConfigurableProperties='todo',
50                                    localizationLanguage='EN_US', create_time=now_time())
51         response = self.client.delete("/openoapi/vnflcm/v1/vnf_instances/1111")
52         self.failUnlessEqual(status.HTTP_500_INTERNAL_SERVER_ERROR, response.status_code)
53         self.assertEqual("No instantiated vnf", response.data["error"])