1 # -------------------------------------------------------------------------
2 # Copyright (c) 2017-2018 AT&T Intellectual Property
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 # -------------------------------------------------------------------------
21 from schematics.exceptions import DataError
23 from apps.placement.models.api.placementRequest import PlacementAPI
24 from apps.placement.models.api.placementResponse import PlacementResponse
25 from apps.slice_selection.models.api.nsi_selection_request import NSISelectionAPI
26 from apps.slice_selection.models.api.nssi_selection_request import NSSISelectionAPI
29 class TestReqValidation(unittest.TestCase):
31 def test_req_validation(self):
32 req_file = "./test/placement-tests/request.json"
33 req_json = json.loads(open(req_file).read())
34 self.assertEqual(PlacementAPI(req_json).validate(), None)
36 def test_req_vfmod_validation(self):
37 req_file = "./test/placement-tests/request_vfmod.json"
38 req_json = json.loads(open(req_file).read())
39 self.assertEqual(PlacementAPI(req_json).validate(), None)
41 def test_req_nsi_validation(self):
42 req_file = "./test/apps/slice_selection/nsi_selection_request.json"
43 req_json = json.loads(open(req_file).read())
44 self.assertEqual(NSISelectionAPI(req_json).validate(), None)
46 def test_req_invalid_nsi(self):
47 req_file = "./test/apps/slice_selection/nsi_selection_invalid_request.json"
48 req_json = json.loads(open(req_file).read())
49 self.assertRaises(DataError, lambda: NSISelectionAPI(req_json).validate())
51 def test_req_nssi_validation(self):
52 req_file = "./test/apps/slice_selection/nssi_selection_request.json"
53 req_json = json.loads(open(req_file).read())
54 self.assertEqual(NSSISelectionAPI(req_json).validate(), None)
56 def test_req_invalid_nssi(self):
57 req_file = "./test/apps/slice_selection/nssi_selection_invalid_request.json"
58 req_json = json.loads(open(req_file).read())
59 self.assertRaises(DataError, lambda: NSSISelectionAPI(req_json).validate())
61 def test_req_failure(self):
63 self.assertRaises(DataError, lambda: PlacementAPI(req_json).validate())
66 class TestResponseValidation(unittest.TestCase):
68 def test_res_validation(self):
69 req_file = "./test/placement-tests/response.json"
70 req_json = json.loads(open(req_file).read())
71 self.assertEqual(PlacementResponse(req_json).validate(), None)
73 def test_res_vfmod_validation(self):
74 req_file = "./test/placement-tests/response_vfmod.json"
75 req_json = json.loads(open(req_file).read())
76 self.assertEqual(PlacementResponse(req_json).validate(), None)
78 def test_invalid_response(self):
80 self.assertRaises(DataError, lambda: PlacementResponse(resp_json).validate())
83 if __name__ == "__main__":