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