aboutsummaryrefslogtreecommitdiffstats
path: root/lcm/ns/tests/test_ns_delete.py
blob: 846b6739bf790ff571ed158fb8a9f1778dc70c2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# Copyright 2017 ZTE Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import json
import uuid

import mock
from django.test import TestCase, Client
from rest_framework import status

from lcm.pub.database.models import NSInstModel
from lcm.pub.utils import restcall


class TestNsDelelete(TestCase):
    def setUp(self):
        self.client = Client()
        self.ns_inst_id = str(uuid.uuid1())
        NSInstModel.objects.filter().delete()
        NSInstModel(id=self.ns_inst_id, nspackage_id="7", nsd_id="2").save()

        # self.nsd_id = str(uuid.uuid4())
        # self.ns_package_id = str(uuid.uuid4())
        # NSDModel(id=self.ns_package_id, nsd_id=self.nsd_id, name='name').save()

    def tearDown(self):
        # NSDModel.objects.all().delete()
        NSInstModel.objects.all().delete()

    @mock.patch.object(restcall, 'call_req')
    def test_delete_ns(self, mock_call_req):
        customer_info = {
            "global-customer-id": "global-customer-id-9b9348f2-f75d-4559-823d-db7ac138ed34",
            "subscriber-name": "subscriber-name-9b9348f2-f75d-4559-823d-db7ac138ed34",
            "subscriber-type": "subscriber-type-9b9348f2-f75d-4559-823d-db7ac138ed34",
            "resource-version": "1505350719754",
            "service-subscriptions": {
                "service-subscription": [
                    {
                        "service-type": "service-type-9b9348f2-f75d-4559-823d-db7ac138ed34",
                        "resource-version": "1505350719887",
                        "service-instances": {
                            "service-instance": [
                                {
                                    "service-instance-id": "service-instance-id-9b9348f2-f75d-4559-823d-db7ac138ed34",
                                    "service-instance-name": "service-instance-name-9b9348f2-f75d-4559-823d-db7ac138ed34",
                                    "service-type": "service-type-9b9348f2-f75d-4559-823d-db7ac138ed34",
                                    "service-role": "service-role-9b9348f2-f75d-4559-823d-db7ac138ed34",
                                    "resource-version": "1505350720009"
                                }
                            ]
                        }
                    }
                ]
            }
        }
        r1_query_ns_to_aai = [0, json.JSONEncoder().encode(customer_info), '200']
        r2_delete_ns_to_aai = [0, json.JSONEncoder().encode({}), '200']
        mock_call_req.side_effect = [r1_query_ns_to_aai, r2_delete_ns_to_aai]
        response = self.client.delete("/api/nslcm/v1/ns/%s" % self.ns_inst_id)
        self.failUnlessEqual(status.HTTP_204_NO_CONTENT, response.status_code)