update link to upper-constraints.txt
[optf/osdf.git] / test / test_api_validation.py
1 # -------------------------------------------------------------------------
2 #   Copyright (c) 2017-2018 AT&T Intellectual Property
3 #
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
7 #
8 #       http://www.apache.org/licenses/LICENSE-2.0
9 #
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.
15 #
16 # -------------------------------------------------------------------------
17 #
18 import json
19 import unittest
20
21 from schematics.exceptions import DataError
22
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
27 from apps.nxi_termination.models.api.nxi_termination_request import NxiTerminationApi
28
29
30 class TestReqValidation(unittest.TestCase):
31
32     def test_req_validation(self):
33         req_file = "./test/placement-tests/request.json"
34         req_json = json.loads(open(req_file).read())
35         self.assertEqual(PlacementAPI(req_json).validate(), None)
36
37     def test_req_vfmod_validation(self):
38         req_file = "./test/placement-tests/request_vfmod.json"
39         req_json = json.loads(open(req_file).read())
40         self.assertEqual(PlacementAPI(req_json).validate(), None)
41
42     def test_req_nsi_validation(self):
43         req_file = "./test/apps/slice_selection/nsi_selection_request.json"
44         req_json = json.loads(open(req_file).read())
45         self.assertEqual(NSISelectionAPI(req_json).validate(), None)
46
47     def test_req_invalid_nsi(self):
48         req_file = "./test/apps/slice_selection/nsi_selection_invalid_request.json"
49         req_json = json.loads(open(req_file).read())
50         self.assertRaises(DataError, lambda: NSISelectionAPI(req_json).validate())
51
52     def test_req_nssi_validation(self):
53         req_file = "./test/apps/slice_selection/nssi_selection_request.json"
54         req_json = json.loads(open(req_file).read())
55         self.assertEqual(NSSISelectionAPI(req_json).validate(), None)
56
57     def test_req_invalid_nssi(self):
58         req_file = "./test/apps/slice_selection/nssi_selection_invalid_request.json"
59         req_json = json.loads(open(req_file).read())
60         self.assertRaises(DataError, lambda: NSSISelectionAPI(req_json).validate())
61
62     def test_req_failure(self):
63         req_json = {}
64         self.assertRaises(DataError, lambda: PlacementAPI(req_json).validate())
65
66     def test_req_nxi_validation(self):
67         req_file = "./test/apps/nxi_termination/nxi_termination.json"
68         req_json = json.loads(open(req_file).read())
69         self.assertEqual(NxiTerminationApi(req_json).validate(), None)
70
71     def test_req_invalid_nxi(self):
72         req_file = "./test/apps/nxi_termination/invalid_request.json"
73         req_json = json.loads(open(req_file).read())
74         self.assertRaises(DataError, lambda: NxiTerminationApi(req_json).validate())
75
76
77 class TestResponseValidation(unittest.TestCase):
78
79     def test_res_validation(self):
80         req_file = "./test/placement-tests/response.json"
81         req_json = json.loads(open(req_file).read())
82         self.assertEqual(PlacementResponse(req_json).validate(), None)
83
84     def test_res_vfmod_validation(self):
85         req_file = "./test/placement-tests/response_vfmod.json"
86         req_json = json.loads(open(req_file).read())
87         self.assertEqual(PlacementResponse(req_json).validate(), None)
88
89     def test_invalid_response(self):
90         resp_json = {}
91         self.assertRaises(DataError, lambda: PlacementResponse(resp_json).validate())
92
93
94 if __name__ == "__main__":
95     unittest.main()