1 # ==================================================================================
2 # Copyright (c) 2019 Nokia
3 # Copyright (c) 2018-2019 AT&T Intellectual Property.
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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 # ==================================================================================
19 from a1 import utils, exceptions
20 import testing_helpers
23 def test_bad_get_ric_manifest(monkeypatch):
25 testing missing manifest
28 def badopen(filename, mode):
29 raise FileNotFoundError()
31 monkeypatch.setattr("builtins.open", badopen)
32 with pytest.raises(exceptions.MissingManifest):
33 utils.get_ric_manifest()
36 def test_bad_get_rmr_mapping(monkeypatch):
38 testing missing rmr mapping
41 def badopen(filename, mode):
42 raise FileNotFoundError()
44 monkeypatch.setattr("builtins.open", badopen)
45 with pytest.raises(exceptions.MissingRmrMapping):
46 utils._get_rmr_mapping_table()
49 def test_good_get_ric_manifest(monkeypatch):
53 testing_helpers.patch_all(monkeypatch)
54 utils.get_ric_manifest()
57 def test_good_get_rmr_mapping(monkeypatch):
59 testing getting the ric maping table
61 testing_helpers.patch_all(monkeypatch)
62 utils._get_rmr_mapping_table()
65 def test_validate(monkeypatch):
67 test json validation wrapper
69 testing_helpers.patch_all(monkeypatch)
70 ricmanifest = utils.get_ric_manifest()
71 schema = ricmanifest["controls"][0]["message_receives_payload_schema"]
72 utils.validate_json(testing_helpers.good_payload(), schema)
73 with pytest.raises(jsonschema.exceptions.ValidationError):
74 utils.validate_json({"dc_admission_start_time": "10:00:00", "dc_admission_end_time": "nevergonnagiveyouup"}, schema)