1 # Copyright 2018 ZTE Corporation.
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
16 from django.test import TestCase, Client
17 from rest_framework import status
18 from lcm.ns_pnfs.biz.get_pnf import GetPnf
19 from lcm.pub.database.models import PNFInstModel
22 class TestGetPnfViews(TestCase):
24 self.client = Client()
29 def test_pnfid_filter(self):
30 pnfId = str(uuid.uuid4())
31 PNFInstModel(pnfId=pnfId,
33 pnfdId=str(uuid.uuid4()),
34 pnfdInfoId=str(uuid.uuid4()),
35 pnfProfileId=str(uuid.uuid4()),
37 "cpInstanceId": str(uuid.uuid4()),
38 "cpdId": "pnf_ext_cp01",
41 pnfInst = GetPnf({"pnfId": pnfId}).do_biz()
42 self.assertEqual("Test PNF", pnfInst[0].pnfName)
44 def test_nsInstanceid_filter(self):
45 pnfId = str(uuid.uuid4())
46 nsInstanceId = str(uuid.uuid4())
47 PNFInstModel(pnfId=pnfId,
49 pnfdId=str(uuid.uuid4()),
50 pnfdInfoId=str(uuid.uuid4()),
51 pnfProfileId=str(uuid.uuid4()),
53 "cpInstanceId": str(uuid.uuid4()),
54 "cpdId": "pnf_ext_cp01",
57 emsId=str(uuid.uuid4()),
58 nsInstances=nsInstanceId
60 pnfInst = GetPnf({"nsInstanceId": nsInstanceId}).do_biz()
61 self.assertEqual("Test PNF", pnfInst[0].pnfName)
63 def test_get_instances_restapi(self):
64 pnfId = str(uuid.uuid4())
65 nsInstanceId = str(uuid.uuid4())
66 PNFInstModel(pnfId=pnfId,
68 pnfdId=str(uuid.uuid4()),
69 pnfdInfoId=str(uuid.uuid4()),
70 pnfProfileId=str(uuid.uuid4()),
72 "cpInstanceId": str(uuid.uuid4()),
73 "cpdId": "pnf_ext_cp01",
76 emsId=str(uuid.uuid4()),
77 nsInstances=nsInstanceId
79 response = self.client.get("/api/nslcm/v1/pnfs")
80 self.assertEqual(status.HTTP_200_OK, response.status_code)
82 def test_get_individual_instance_restapi(self):
83 pnfId = str(uuid.uuid4())
84 nsInstanceId = str(uuid.uuid4())
85 PNFInstModel(pnfId=pnfId,
87 pnfdId=str(uuid.uuid4()),
88 pnfdInfoId=str(uuid.uuid4()),
89 pnfProfileId=str(uuid.uuid4()),
91 "cpInstanceId": str(uuid.uuid4()),
92 "cpdId": "pnf_ext_cp01",
95 emsId=str(uuid.uuid4()),
96 nsInstances=nsInstanceId
98 response = self.client.get("/api/nslcm/v1/pnfs/%s" % pnfId)
99 self.assertEqual(status.HTTP_200_OK, response.status_code)