Aligned test with updated R-610030
[vvp/validation-scripts.git] / ice_validator / tests / test_heat_template_structure.py
1 # -*- coding: utf8 -*-
2 # ============LICENSE_START====================================================
3 # org.onap.vvp/validation-scripts
4 # ===================================================================
5 # Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 # ===================================================================
7 #
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
12 #
13 #             http://www.apache.org/licenses/LICENSE-2.0
14 #
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.
20 #
21 #
22 #
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
27 #
28 #             https://creativecommons.org/licenses/by/4.0/
29 #
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.
35 #
36 # ============LICENSE_END============================================
37 #
38 #
39
40 """Test heat template structure
41 """
42 import pytest
43
44 from tests import cached_yaml as yaml
45 from .helpers import validates, is_base_module, load_yaml
46
47 VERSION = "1.2.0"
48
49 # pylint: disable=invalid-name
50
51
52 @validates("R-27078")
53 def test_heat_template_structure_contains_heat_template_version(yaml_file):
54     """
55     Check that all heat templates have the required sections
56     """
57     template = load_yaml(yaml_file)
58     assert (
59         "heat_template_version" in template
60     ), "This template must contain a heat_template_version section"
61
62
63 @validates("R-39402")
64 def test_heat_template_structure_contains_description(yaml_file):
65     """
66     Check that all heat templates have the required sections
67     """
68     template = load_yaml(yaml_file)
69     assert "description" in template, "This template must contain a description section"
70
71
72 @validates("R-35414")
73 def test_heat_template_structure_contains_parameters(yaml_file):
74     """
75     Check that all heat templates have the required sections
76     """
77     if is_base_module(yaml_file):
78         pytest.skip("Not applicable to base modules")
79     template = load_yaml(yaml_file)
80     assert "parameters" in template and len(
81         template["parameters"].keys()
82     ), "This template must contain a parameters section"
83
84
85 @validates("R-23664")
86 def test_heat_template_structure_contains_resources(heat_template):
87     """
88     Check that all heat templates have the required sections
89     """
90     if is_base_module(heat_template):
91         pytest.skip("Not applicable to base modules")
92     template = load_yaml(heat_template)
93     assert "resources" in template, "This template must contain a resources section"
94
95
96 @validates("R-11441")
97 def test_parameter_type(yaml_file):
98     """A VNF's Heat Orchestration Template's parameter type **MUST**
99     be one of the following values:
100     """
101     types = ["string", "number", "json", "comma_delimited_list", "boolean"]
102     with open(yaml_file) as fh:
103         yml = yaml.load(fh)
104     for key, param in yml.get("parameters", {}).items():
105         assert isinstance(param, dict), "%s parameter %s is not dict" % (yaml_file, key)
106         if "type" not in param:
107             continue
108         typ = param["type"]
109         assert typ in types, '%s parameter %s has invalid type "%s"' % (
110             yaml_file,
111             key,
112             typ,
113         )