update link to upper-constraints.txt
[vfc/nfvo/lcm.git] / lcm / ns_pnfs / tests / test_delete_pnf.py
1 # Copyright 2018 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 uuid
16 from django.test import TestCase, Client
17 from rest_framework import status
18 from lcm.ns_pnfs.biz.delete_pnf import DeletePnf
19 from lcm.pub.database.models import PNFInstModel
20
21
22 class TestDeletePnfViews(TestCase):
23     def setUp(self):
24         self.client = Client()
25
26     def tearDown(self):
27         pass
28
29     def test_do_biz(self):
30         pnfId = str(uuid.uuid4())
31         PNFInstModel(pnfId=pnfId,
32                      pnfName="Test PNF",
33                      pnfdId=str(uuid.uuid4()),
34                      pnfdInfoId=str(uuid.uuid4()),
35                      pnfProfileId=str(uuid.uuid4()),
36                      cpInfo=[{
37                          "cpInstanceId": str(uuid.uuid4()),
38                          "cpdId": "pnf_ext_cp01",
39                          "cpProtocolData": []
40                      }]).save()
41         DeletePnf(pnfId).do_biz()
42         pnfInst = PNFInstModel.objects.filter(pnfId=pnfId)
43         self.assertEqual(0, len(pnfInst))
44
45     def test_rest_api(self):
46         pnfId = str(uuid.uuid4())
47         PNFInstModel(pnfId=pnfId,
48                      pnfName="Test PNF",
49                      pnfdId=str(uuid.uuid4()),
50                      pnfdInfoId=str(uuid.uuid4()),
51                      pnfProfileId=str(uuid.uuid4()),
52                      cpInfo=[{
53                          "cpInstanceId": str(uuid.uuid4()),
54                          "cpdId": "pnf_ext_cp01",
55                          "cpProtocolData": []
56                      }]).save()
57         response = self.client.delete("/api/nslcm/v1/pnfs/%s" % pnfId)
58         self.assertEqual(status.HTTP_204_NO_CONTENT, response.status_code)