Add code and testcase of query single vnf
[vfc/gvnfm/vnflcm.git] / lcm / lcm / nf / vnfs / tests / test_vnf_query.py
1 # Copyright 2017 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 from django.test import TestCase, Client
15 from rest_framework import status
16
17 from lcm.pub.database.models import NfInstModel, StorageInstModel
18
19
20 class ResourceTest(TestCase):
21     def setUp(self):
22         self.client = Client()
23         self.nf_inst_id = "01"
24         NfInstModel.objects.all().delete()
25         self.test_data = {
26             "vnfInstanceId": "1",
27             "vnfInstanceName": "VNF1",
28             "vnfProvider": None,
29             "instantiatedVnfInfo": {
30                 "vnfState": None,
31                 "extCpInfo": [],
32                 "virtualStorageResourceInfo": [
33                     {
34                         "virtualStorageInstanceId": "s02",
35                         "storageResource": {
36                             "resourceId": "resource01",
37                             "vimId": "vim01"
38                         }
39                     }
40                 ],
41                 "extVirtualLink": [],
42                 "vnfcResourceInfo": [],
43                 "monitoringParameters": {},
44                 "vimInfo": [],
45                 "flavourId": None,
46                 "virtualLinkResourceInfo": [],
47                 "scaleStatus": []
48             },
49             "vnfdVersion": None,
50             "onboardedVnfPkgInfoId": None
51         }
52
53     def tearDown(self):
54         pass
55
56     def test_get_vnf(self):
57         vnf_inst_id = "1"
58         NfInstModel(nfinstid=vnf_inst_id, nf_name='VNF1').save()
59         StorageInstModel(storageid='s02', vimid='vim01', resouceid='resource01', insttype=1, \
60                          instid=vnf_inst_id).save()
61         response = self.client.get("/openoapi/vnflcm/v1/vnf_instances/%s" % vnf_inst_id, format='json')
62         self.assertEqual(response.status_code, status.HTTP_200_OK)
63         self.assertEqual(self.test_data, response.data)