1 # Copyright 2018 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.
16 from rest_framework import status
17 from django.test import Client
18 from django.test import TestCase
19 from lcm.pub.database.models import FPInstModel, VNFFGInstModel
20 from lcm.ns_sfcs.tests.test_data import nsd_model
23 class TestSfcInstance(TestCase):
25 self.client = Client()
27 "nsInstanceId": "ns_inst_1",
28 "context": json.dumps(nsd_model),
30 "sdnControllerId": "sdnControllerId_1"
32 VNFFGInstModel.objects.all().delete()
33 FPInstModel.objects.all().delete()
34 VNFFGInstModel(vnffgdid="vnffg_id1", vnffginstid="vnffg_inst_1", nsinstid="ns_inst_1", endpointnumber=2,
35 vllist="vlinst1", cplist="cp1", vnflist="vnf1,vnf2", fplist="fp1").save()
38 VNFFGInstModel.objects.all().delete()
39 FPInstModel.objects.all().delete()
41 def test_sfc_instance_success(self):
42 resp = self.client.post("/api/nslcm/v1/ns/sfc_instance", self.data, format="json")
44 self.assertEqual(resp.status_code, status.HTTP_200_OK)
45 vnffg = VNFFGInstModel.objects.get(vnffginstid="vnffg_inst_1")
46 self.assertEqual(vnffg.fplist, "fp1," + resp.data["fpinstid"])
47 ret = FPInstModel.objects.get(fpinstid=resp.data["fpinstid"])
48 self.assertIsNotNone(ret)
50 def test_sfc_instance_when_request_data_is_not_valid(self):
52 resp = self.client.post("/api/nslcm/v1/ns/sfc_instance", data, format="json")
53 self.assertEqual(resp.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
55 def test_sfc_instance_when_error_request_data(self):
56 data = copy.deepcopy(self.data)
58 resp = self.client.post("/api/nslcm/v1/ns/sfc_instance", data, format="json")
60 self.assertEqual(resp.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
62 def test_sfc_instance_when_no_fp_model(self):
63 data = copy.deepcopy(self.data)
64 data["context"] = json.dumps({"fps": []})
65 resp = self.client.post("/api/nslcm/v1/ns/sfc_instance", data, format="json")
67 self.assertEqual(resp.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)