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.
18 from django.test import TestCase, Client
19 from lcm.pub.database.models import NSInstModel
20 from lcm.pub.utils import restcall
21 from rest_framework import status
22 from lcm.ns.tests import NS_INFO_AAI_DICT
25 class TestNsDelelete(TestCase):
27 self.client = Client()
28 self.ns_inst_id = str(uuid.uuid1())
29 NSInstModel.objects.filter().delete()
30 NSInstModel(id=self.ns_inst_id, nspackage_id="7", nsd_id="2").save()
33 NSInstModel.objects.all().delete()
35 @mock.patch.object(restcall, 'call_req')
36 def test_delete_ns(self, mock_call_req):
37 r1_query_ns_to_aai = [0, json.JSONEncoder().encode(NS_INFO_AAI_DICT), '200']
38 r2_delete_ns_to_aai = [0, json.JSONEncoder().encode({}), '200']
39 mock_call_req.side_effect = [r1_query_ns_to_aai, r2_delete_ns_to_aai]
40 response = self.client.delete("/api/nslcm/v1/ns/%s" % self.ns_inst_id)
41 self.assertEqual(status.HTTP_204_NO_CONTENT, response.status_code)