Add unit test for vnf Grant
[vfc/nfvo/lcm.git] / lcm / v2 / tests.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 unittest
16 import json
17 from django.test import Client
18 from rest_framework import status
19
20
21 class VnfGrantViewTest(unittest.TestCase):
22     def setUp(self):
23         self.client = Client()
24
25     def tearDown(self):
26         pass
27
28     def test_grant_vnf_normal(self):
29         data = {
30             "vnfInstanceId": "1",
31             "vnfLcmOpOccId": "2",
32             "vnfdId": "3",
33             "flavourId": "4",
34             "operation": "INSTANTIATE",
35             "isAutomaticInvocation": True,
36             "instantiationLevelId": "5",
37             "addResources": [
38                 {
39                     "id": "1",
40                     "type": "COMPUTE",
41                     "vduId": "2",
42                     "resourceTemplateId": "3",
43                     "resource": {
44                         "vimConnectionId": "4",
45                         "resourceProviderId": "5",
46                         "resourceId": "6",
47                         "vimLevelResourceType": "7"
48                     }
49                 }
50             ],
51             "placementConstraints": [
52                 {
53                     "affinityOrAntiAffinity": "AFFINITY",
54                     "scope": "NFVI_POP",
55                     "resource": [
56                         {
57                             "idType": "RES_MGMT",
58                             "resourceId": "1",
59                             "vimConnectionId": "2",
60                             "resourceProviderId": "3"
61                         }
62                     ]
63                 }
64             ],
65             "vimConstraints": [
66                 {
67                     "sameResourceGroup": True,
68                     "resource": [
69                         {
70                             "idType": "RES_MGMT",
71                             "resourceId": "1",
72                             "vimConnectionId": "2",
73                             "resourceProviderId": "3"
74                         }
75                     ]
76                 }
77             ],
78             "additionalParams": {},
79             "_links": {
80                 "vnfLcmOpOcc": {
81                     "href": "1"
82                 },
83                 "vnfInstance": {
84                     "href": "2"
85                 }
86             }
87         }
88         response = self.client.post("/api/nslcm/v2/grants", data=data, format='json')
89         self.assertEqual(status.HTTP_201_CREATED, response.status_code, response.content)
90         resp_data = json.loads(response.content)
91         expect_resp_data = {
92             "id": resp_data.get("id"),
93             "vnfInstanceId": "1",
94             "vnfLcmOpOccId": "2"
95         }
96         self.assertEqual(expect_resp_data, resp_data)