fix creat pnf error
[vfc/nfvo/lcm.git] / lcm / ns_pnfs / tests / test_create_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 import mock
17 import json
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
22
23
24 class TestCreatePnfViews(TestCase):
25     def setUp(self):
26         self.client = Client()
27
28     def tearDown(self):
29         pass
30
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()),
35             'pnfdId': 'test',
36             'pnfdName': 'test',
37             'pnfdVersion': 'v1.1.0',
38             'pnfdProvider': 'ZTE',
39             'pnfdInvariantId': str(uuid.uuid4())
40         }), '200']
41         id = str(uuid.uuid4())
42         data = {
43             "pnfId": id,
44             "pnfName": "Test PNF",
45             "pnfdId": str(uuid.uuid4()),
46             "pnfdInfoId": str(uuid.uuid4()),
47             "pnfProfileId": str(uuid.uuid4()),
48             "cpInfo": [
49                 {
50                     "cpInstanceId": str(uuid.uuid4()),
51                     "cpdId": "pnf_ext_cp01",
52                     "cpProtocolData": []
53                 }
54             ],
55             "emsId": str(uuid.uuid4()),
56             "nsInstances": str(uuid.uuid4()) + "," + str(uuid.uuid4())
57         }
58         ret = CreatePnf(data).do_biz()
59         self.assertIsNotNone(ret)
60
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()),
65             'pnfdId': 'test',
66             'pnfdName': 'test',
67             'pnfdVersion': 'v1.1.0',
68             'pnfdProvider': 'ZTE',
69             'pnfdInvariantId': str(uuid.uuid4())
70         }), '200']
71         id = str(uuid.uuid4())
72         data = {
73             "pnfId": id,
74             "pnfName": "Test PNF",
75             "pnfdId": str(uuid.uuid4()),
76             "pnfdInfoId": str(uuid.uuid4()),
77             "pnfProfileId": str(uuid.uuid4()),
78             "cpInfo": [
79                 {
80                     "cpInstanceId": str(uuid.uuid4()),
81                     "cpdId": "pnf_ext_cp01",
82                     "cpProtocolData": []
83                 }
84             ],
85             "emsId": str(uuid.uuid4()),
86             "nsInstances": str(uuid.uuid4())
87         }
88
89         response = self.client.post("/api/nslcm/v1/pnfs", data=data, format='json')
90         self.assertEqual(status.HTTP_201_CREATED, response.status_code)
91
92         data = {
93             "pnfId": id,
94             "pnfName": "Test PNF",
95             "pnfdId": str(uuid.uuid4()),
96             "pnfdInfoId": str(uuid.uuid4()),
97             "pnfProfileId": str(uuid.uuid4()),
98             "cpInfo": [
99                 {
100                     "cpInstanceId": str(uuid.uuid4()),
101                     "cpdId": "pnf_ext_cp01",
102                     "cpProtocolData": []
103                 }
104             ],
105             "emsId": str(uuid.uuid4()),
106             "nsInstances": str(uuid.uuid4())
107         }
108
109         response = self.client.post("/api/nslcm/v1/pnfs", data=data, format='json')
110         self.assertEqual(status.HTTP_201_CREATED, response.status_code)