Merge "Dockerize osdf simulators for csit"
[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 osdf.models.api.placementRequest import PlacementAPI
22 from osdf.models.api.placementResponse import PlacementResponse
23 from schematics.exceptions import ModelValidationError
24
25
26 class TestReqValidation(unittest.TestCase):
27
28     def test_req_validation(self):
29         req_file = "./test/placement-tests/request.json"
30         req_json = json.loads(open(req_file).read())
31         self.assertEqual(PlacementAPI(req_json).validate(), None)
32
33     def test_req_failure(self):
34         req_json = {}
35         self.assertRaises(ModelValidationError, lambda: PlacementAPI(req_json).validate())
36
37
38 class TestResponseValidation(unittest.TestCase):
39
40     def test_res_validation(self):
41         req_file = "./test/placement-tests/response.json"
42         req_json = json.loads(open(req_file).read())
43         self.assertEqual(PlacementResponse(req_json).validate(), None)
44
45     def test_invalid_response(self):
46         resp_json = {}
47         self.assertRaises(ModelValidationError, lambda: PlacementResponse(resp_json).validate())
48
49
50 if __name__ == "__main__":
51     unittest.main()