Update python2 to python3
[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 uuid
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
23
24
25 class TestNsDelelete(TestCase):
26     def setUp(self):
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()
31
32     def tearDown(self):
33         NSInstModel.objects.all().delete()
34
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)