1 # Copyright 2017 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.
19 from django.test import TestCase, Client
20 from rest_framework import status
22 from lcm.pub.database.models import NSInstModel
23 from lcm.pub.utils import restcall
26 class TestNsDelelete(TestCase):
28 self.client = Client()
29 self.ns_inst_id = str(uuid.uuid1())
30 NSInstModel.objects.filter().delete()
31 NSInstModel(id=self.ns_inst_id, nspackage_id="7", nsd_id="2").save()
34 NSInstModel.objects.all().delete()
36 @mock.patch.object(restcall, 'call_req')
37 def test_delete_ns(self, mock_call_req):
39 "service-instance-id": "service-instance-id-9b9348f2-f75d-4559-823d-db7ac138ed34",
40 "service-instance-name": "service-instance-name-9b9348f2-f75d-4559-823d-db7ac138ed34",
41 "service-type": "service-type-9b9348f2-f75d-4559-823d-db7ac138ed34",
42 "service-role": "service-role-9b9348f2-f75d-4559-823d-db7ac138ed34",
43 "resource-version": "1505350720009"
45 r1_query_ns_to_aai = [0, json.JSONEncoder().encode(ns_info), '200']
46 r2_delete_ns_to_aai = [0, json.JSONEncoder().encode({}), '200']
47 mock_call_req.side_effect = [r1_query_ns_to_aai, r2_delete_ns_to_aai]
48 response = self.client.delete("/api/nslcm/v1/ns/%s" % self.ns_inst_id)
49 self.failUnlessEqual(status.HTTP_204_NO_CONTENT, response.status_code)