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.
18 from django.test import TestCase, Client
19 from rest_framework import status
20 from lcm.ns_pnfs.biz.create_pnf import CreatePnf
21 from lcm.pub.utils import restcall
24 class TestCreatePnfViews(TestCase):
26 self.client = Client()
31 @mock.patch.object(restcall, 'call_req')
32 def test_do_biz(self, mock_call_req):
33 mock_call_req.return_value = [0, json.JSONEncoder().encode({
34 'id': str(uuid.uuid4()),
37 'pnfdVersion': 'v1.1.0',
38 'pnfdProvider': 'ZTE',
39 'pnfdInvariantId': str(uuid.uuid4())
41 id = str(uuid.uuid4())
44 "pnfName": "Test PNF",
45 "pnfdId": str(uuid.uuid4()),
46 "pnfdInfoId": str(uuid.uuid4()),
47 "pnfProfileId": str(uuid.uuid4()),
50 "cpInstanceId": str(uuid.uuid4()),
51 "cpdId": "pnf_ext_cp01",
55 "emsId": str(uuid.uuid4()),
56 "nsInstances": str(uuid.uuid4()) + "," + str(uuid.uuid4())
58 ret = CreatePnf(data).do_biz()
59 self.assertIsNotNone(ret)
61 @mock.patch.object(restcall, 'call_req')
62 def test_rest_api(self, mock_call_req):
63 mock_call_req.return_value = [0, json.JSONEncoder().encode({
64 'id': str(uuid.uuid4()),
67 'pnfdVersion': 'v1.1.0',
68 'pnfdProvider': 'ZTE',
69 'pnfdInvariantId': str(uuid.uuid4())
71 id = str(uuid.uuid4())
74 "pnfName": "Test PNF",
75 "pnfdId": str(uuid.uuid4()),
76 "pnfdInfoId": str(uuid.uuid4()),
77 "pnfProfileId": str(uuid.uuid4()),
80 "cpInstanceId": str(uuid.uuid4()),
81 "cpdId": "pnf_ext_cp01",
85 "emsId": str(uuid.uuid4()),
86 "nsInstances": str(uuid.uuid4())
89 response = self.client.post("/api/nslcm/v1/pnfs", data=data, format='json')
90 self.assertEqual(status.HTTP_201_CREATED, response.status_code)
94 "pnfName": "Test PNF",
95 "pnfdId": str(uuid.uuid4()),
96 "pnfdInfoId": str(uuid.uuid4()),
97 "pnfProfileId": str(uuid.uuid4()),
100 "cpInstanceId": str(uuid.uuid4()),
101 "cpdId": "pnf_ext_cp01",
105 "emsId": str(uuid.uuid4()),
106 "nsInstances": str(uuid.uuid4())
109 response = self.client.post("/api/nslcm/v1/pnfs", data=data, format='json')
110 self.assertEqual(status.HTTP_201_CREATED, response.status_code)