2032865d1c2393d99f08ec863cb42fac30c5ca54
[vfc/nfvo/lcm.git] / lcm / ns_sfcs / tests / test_sfc_instance.py
1 # Copyright 2018 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 import json
15 import copy
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
21
22
23 class TestSfcInstance(TestCase):
24     def setUp(self):
25         self.client = Client()
26         self.data = {
27             "nsInstanceId": "ns_inst_1",
28             "context": json.dumps(nsd_model),
29             "fpindex": "fpd_1",
30             "sdnControllerId": "sdnControllerId_1"
31         }
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()
36
37     def tearDown(self):
38         VNFFGInstModel.objects.all().delete()
39         FPInstModel.objects.all().delete()
40
41     def test_sfc_instance_success(self):
42         pass
43     #     resp = self.client.post("/api/nslcm/v1/ns/sfc_instance", self.data, format="json")
44     #
45     #     self.assertEqual(resp.status_code, status.HTTP_200_OK)
46     #     vnffg = VNFFGInstModel.objects.get(vnffginstid="vnffg_inst_1")
47     #     self.assertEqual(vnffg.fplist, "fp1," + resp.data["fpinstid"])
48     #     ret = FPInstModel.objects.get(fpinstid=resp.data["fpinstid"])
49     #     self.assertIsNotNone(ret)
50
51     def test_sfc_instance_when_request_data_is_not_valid(self):
52         data = {}
53         resp = self.client.post("/api/nslcm/v1/ns/sfc_instance", data, format="json")
54         self.assertEqual(resp.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
55
56     def test_sfc_instance_when_error_request_data(self):
57         data = copy.deepcopy(self.data)
58         data.pop("fpindex")
59         resp = self.client.post("/api/nslcm/v1/ns/sfc_instance", data, format="json")
60
61         self.assertEqual(resp.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
62
63     def test_sfc_instance_when_no_fp_model(self):
64         data = copy.deepcopy(self.data)
65         data["context"] = json.dumps({"fps": []})
66         resp = self.client.post("/api/nslcm/v1/ns/sfc_instance", data, format="json")
67
68         self.assertEqual(resp.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)