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
28 class TestReqValidation(unittest.TestCase):
30 def test_req_validation(self):
31 req_file = "./test/placement-tests/request.json"
32 req_json = json.loads(open(req_file).read())
33 self.assertEqual(PlacementAPI(req_json).validate(), None)
35 def test_req_vfmod_validation(self):
36 req_file = "./test/placement-tests/request_vfmod.json"
37 req_json = json.loads(open(req_file).read())
38 self.assertEqual(PlacementAPI(req_json).validate(), None)
40 def test_req_nsi_validation(self):
41 req_file = "./test/apps/slice_selection/nsi_selection_request.json"
42 req_json = json.loads(open(req_file).read())
43 self.assertEqual(NSISelectionAPI(req_json).validate(), None)
45 def test_req_invalid_nsi(self):
46 req_file = "./test/apps/slice_selection/nsi_selection_invalid_request.json"
47 req_json = json.loads(open(req_file).read())
48 self.assertRaises(DataError, lambda: NSISelectionAPI(req_json).validate())
50 def test_req_failure(self):
52 self.assertRaises(DataError, lambda: PlacementAPI(req_json).validate())
55 class TestResponseValidation(unittest.TestCase):
57 def test_res_validation(self):
58 req_file = "./test/placement-tests/response.json"
59 req_json = json.loads(open(req_file).read())
60 self.assertEqual(PlacementResponse(req_json).validate(), None)
62 def test_res_vfmod_validation(self):
63 req_file = "./test/placement-tests/response_vfmod.json"
64 req_json = json.loads(open(req_file).read())
65 self.assertEqual(PlacementResponse(req_json).validate(), None)
67 def test_invalid_response(self):
69 self.assertRaises(DataError, lambda: PlacementResponse(resp_json).validate())
72 if __name__ == "__main__":