544c37431b16083e925bc4b6d4a9ee110e63d4a0
[vfc/nfvo/lcm.git] / lcm / ns / tests / test_ns_instant.py
1 # Copyright 2016 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 rest_framework import status
15 from django.test import TestCase
16 from django.test import Client
17
18 from lcm.pub.database.models import NSInstModel
19
20
21 class TestNsInstant(TestCase):
22     def setUp(self):
23         self.client = Client()
24         NSInstModel.objects.filter().delete()
25         self.context = '{"vnfs": ["a", "b"], "sfcs": ["c"], "vls": ["d", "e", "f"]}'
26         NSInstModel(id="123", nspackage_id="7", nsd_id="2").save()
27
28     def tearDown(self):
29         pass
30
31     """
32     @mock.patch.object(restcall, 'call_req')
33     @mock.patch.object(toscautil, 'convert_nsd_model')
34     def test_ns_instant_ok(self, mock_convert_nsd_model, mock_call_req):
35         mock_convert_nsd_model.return_value = self.context
36         mock_vals = {
37             "/api/catalog/v1/csars/7/files?relativePath=abc.yaml":
38                 [0, '{"downloadUri":"http://test.yaml", "localPath":"./test.yaml"}', '200'],
39             "/api/tosca/v1/indirect/plan":
40                 [0, '{"description":"", "metadata":{}, "nodes":[]}', '200'],
41             "/api/catalog/v1/servicetemplates/2/operations":
42                 [0, '[{"name":"LCM", "processId":"{http://www.open-o.org/tosca/nfv/2015/12}init-16"}]', '200'],
43             "/api/wso2bpel/v1/process/instance":
44                 [0, '{"status": 1}', '200']}
45
46         def side_effect(*args):
47             return mock_vals[args[4]]
48
49         mock_call_req.side_effect = side_effect
50
51         data = {'iaUrl': "", 'vnfmId': "", 'context': "{\"e\":{\"f\":\"4\"}}", 'statusUrl': "",
52                 'serviceTemplateId': "", 'roUrl': "", 'containerapiUrl': "", 'flavor': "",
53                 'nsInstanceId': "123", 'instanceId': "234", 'resourceUrl': "", 'callbackId': "",
54                 'additionalParamForVnf': "[{\"b\":1},{\"c\":{\"d\":\"2\"}}]",
55                 'additionalParamForNs': "[{\"a\":3},{\"e\":{\"f\":\"4\"}}]", 'flavorParams': ""}
56         resp = self.client.post("/api/nslcm/v1/ns/123/instantiate", data, format='json')
57         self.assertEqual(resp.status_code, status.HTTP_200_OK)
58     """
59
60     def test_swagger_ok(self):
61         resp = self.client.get("/api/nslcm/v1/swagger.json", format='json')
62         self.assertEqual(resp.status_code, status.HTTP_200_OK)