move heal test json from code to indepandent file
[vfc/nfvo/lcm.git] / lcm / ns / tests / test_ns_delete.py
1 # Copyright 2017 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
15 import json
16 import mock
17 import os
18 import uuid
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
23
24
25 class TestNsDelelete(TestCase):
26     def setUp(self):
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()
32
33     def tearDown(self):
34         NSInstModel.objects.all().delete()
35
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)