2 # ============LICENSE_START====================================================
3 # org.onap.vvp/validation-scripts
4 # ===================================================================
5 # Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 # ===================================================================
8 # Unless otherwise specified, all software contained herein is licensed
9 # under the Apache License, Version 2.0 (the "License");
10 # you may not use this software except in compliance with the License.
11 # You may obtain a copy of the License at
13 # http://www.apache.org/licenses/LICENSE-2.0
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS,
17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 # See the License for the specific language governing permissions and
19 # limitations under the License.
23 # Unless otherwise specified, all documentation contained herein is licensed
24 # under the Creative Commons License, Attribution 4.0 Intl. (the "License");
25 # you may not use this documentation except in compliance with the License.
26 # You may obtain a copy of the License at
28 # https://creativecommons.org/licenses/by/4.0/
30 # Unless required by applicable law or agreed to in writing, documentation
31 # distributed under the License is distributed on an "AS IS" BASIS,
32 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33 # See the License for the specific language governing permissions and
34 # limitations under the License.
36 # ============LICENSE_END============================================
38 # ECOMP is a trademark and service mark of AT&T Intellectual Property.
41 """ environment file structure
47 from .helpers import validates
51 # pylint: disable=invalid-name
54 def test_environment_structure(env_file):
56 Check that all environments files only have the allowed sections
61 "encrypted_parameters",
62 "parameter_merge_strategies",
65 with open(env_file) as fh:
67 assert [k for k in key_values if k in yml], "%s missing any of %s" % (
74 def test_environment_file_contains_required_sections(env_file):
76 Check that all environments files only have the allowed sections
78 required_keys = ["parameters"]
80 with open(env_file) as fh:
82 missing_keys = [v for v in required_keys if v not in yml]
83 assert not missing_keys, "%s missing %s" % (env_file, missing_keys)
86 def test_environment_file_sections_have_the_right_format(env_file):
88 Check that all environment files have sections of the right format.
89 Do note that it only tests for dicts or not dicts currently.
91 dict_keys = ["parameters", "encrypted_parameters", "parameter_merge_strategies"]
92 not_dict_keys = ["event_sinks"]
94 with open(env_file) as fh:
97 if not [k for k in dict_keys + not_dict_keys if k in yml]:
98 pytest.skip("The fixture is not applicable for this test")
100 bad_dict_keys = [k for k in dict_keys if k in yml and not isinstance(yml[k], dict)]
101 bad_not_dict_keys = [
102 k for k in not_dict_keys if k in yml and isinstance(yml[k], dict)
106 errors.append("must be dict %s" % bad_dict_keys)
107 if bad_not_dict_keys:
108 errors.append("must not be dict %s" % bad_not_dict_keys)
109 assert not errors, "%s errors:\n %s" % (env_file, "\n ".join(errors))