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 lcm.pub.database.models import NSInstModel
21 from lcm.pub.utils import restcall, fileutil
22 from rest_framework import status
25 class TestNsDelelete(TestCase):
27 self.client = Client()
28 self.ns_inst_id = str(uuid.uuid1())
29 self.cur_path = os.path.dirname(os.path.abspath(__file__))
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):
38 ns_info_aai = fileutil.read_json_file(self.cur_path + '/data/ns_info_aai.json')
39 r1_query_ns_to_aai = [0, json.JSONEncoder().encode(ns_info_aai), '200']
40 r2_delete_ns_to_aai = [0, json.JSONEncoder().encode({}), '200']
41 mock_call_req.side_effect = [r1_query_ns_to_aai, r2_delete_ns_to_aai]
42 response = self.client.delete("/api/nslcm/v1/ns/%s" % self.ns_inst_id)
43 self.failUnlessEqual(status.HTTP_204_NO_CONTENT, response.status_code)