1 # Copyright 2019 ZTE Corporation.
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
18 from django.test import TestCase, Client
19 from rest_framework import status
20 from rest_framework.test import APIClient
21 from lcm.pub.database.models import NSInstModel
22 from lcm.pub.utils import restcall
25 class TestNsInstanceApi(TestCase):
27 self.client = Client()
28 self.apiClient = APIClient()
30 self.ns_instances_url = '/api/nslcm/v1/ns_instances'
31 self.nsd_id = str(uuid.uuid4())
32 self.ns_package_id = str(uuid.uuid4())
35 NSInstModel.objects.all().delete()
37 @mock.patch.object(restcall, 'call_req')
38 def test_create_ns(self, mock_call_req):
40 "csarId": self.ns_package_id,
42 "nsPackageId": self.ns_package_id,
46 r1_query_nspackage_from_catalog = [0, json.JSONEncoder().encode(nspackage_info), '201']
47 r2_create_ns_to_aai = [0, json.JSONEncoder().encode({}), '201']
48 mock_call_req.side_effect = [r1_query_nspackage_from_catalog, r2_create_ns_to_aai]
51 'HTTP_GLOBALCUSTOMERID': 'global-customer-id-test1',
52 'HTTP_SERVICETYPE': 'service-type-test1'
58 "nsDescription": "description"
60 response = self.apiClient.post(self.ns_instances_url, data=data, format=self.format, **header)
62 self.failUnlessEqual(status.HTTP_201_CREATED, response.status_code)