Add sonar pom and tox hooks.
[ric-plt/a1.git] / tests / test_utils.py
1 # ==================================================================================
2 #       Copyright (c) 2019 Nokia
3 #       Copyright (c) 2018-2019 AT&T Intellectual Property.
4 #
5 #   Licensed under the Apache License, Version 2.0 (the "License");
6 #   you may not use this file except in compliance with the License.
7 #   You may obtain a copy of the License at
8 #
9 #          http://www.apache.org/licenses/LICENSE-2.0
10 #
11 #   Unless required by applicable law or agreed to in writing, software
12 #   distributed under the License is distributed on an "AS IS" BASIS,
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 #   See the License for the specific language governing permissions and
15 #   limitations under the License.
16 # ==================================================================================
17 import pytest
18 import jsonschema
19 from a1 import utils, exceptions
20 import testing_helpers
21
22
23 def test_bad_get_ric_manifest(monkeypatch):
24     """
25     testing missing manifest
26     """
27
28     def badopen(filename, mode):
29         raise FileNotFoundError()
30
31     monkeypatch.setattr("builtins.open", badopen)
32     with pytest.raises(exceptions.MissingManifest):
33         utils.get_ric_manifest()
34
35
36 def test_good_get_ric_manifest(monkeypatch):
37     """
38     test get_ric_manifest
39     """
40     testing_helpers.patch_all(monkeypatch)
41     utils.get_ric_manifest()
42
43
44 def test_validate(monkeypatch):
45     """
46     test json validation wrapper
47     """
48     testing_helpers.patch_all(monkeypatch)
49     ricmanifest = utils.get_ric_manifest()
50     schema = ricmanifest["controls"][0]["message_receives_payload_schema"]
51     utils.validate_json(testing_helpers.good_payload(), schema)
52     with pytest.raises(jsonschema.exceptions.ValidationError):
53         utils.validate_json({"dc_admission_start_time": "10:00:00", "dc_admission_end_time": "nevergonnagiveyouup"}, schema)