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============================================
39 from io import StringIO
44 from config import Config, get_generator_plugin_names, to_uri
49 namespace: {namespace}
52 app-name: VNF Validation Tool
53 requirement-link-url: http://requirement.url.com
55 - name: Environment File Compliance. (Required to Onboard)
56 category: environment_file
58 Checks certain parameters are excluded from the .env file, per HOT Requirements.
59 Required for ASDC onboarding, not needed for manual Openstack testing.
61 polling-freqency: 1000
63 - tests.test_environment_file_parameters.ENV_PARAMETER_SPEC
66 path: path/to/terms.txt
67 popup-title: Terms and Conditions
68 popup-link-text: View Terms and Conditions
69 popup-msg-text: Review and Accept the Terms
73 # noinspection PyShadowingNames
76 unique = str(uuid.uuid4())
77 data = DEFAULT_CONFIG.format(namespace=unique)
78 return Config(yaml.safe_load(StringIO(data)))
81 def test_app_name(config):
82 assert "VNF Validation Tool" in config.app_name
83 assert vvp.VERSION in config.app_name
86 def test_categories_names_length(config):
87 names = config.category_names
88 assert len(names) == 1
89 assert names[0] == "Environment File Compliance. (Required to Onboard)"
92 def test_polling_frequency(config):
93 assert config.polling_frequency == 1000
96 def test_get_category_when_other(config):
98 config.get_category("Environment File Compliance. (Required to Onboard)")
103 def test_queues(config):
104 assert config.log_queue.empty(), "Log should start empty"
105 config.log_file.write("Test")
106 assert config.log_queue.get() == "Test"
108 assert config.status_queue.empty(), "status should start empty"
109 config.status_queue.put((True, None))
110 assert config.status_queue.get() == (True, None)
113 MISSING_CATEGORY_FIELD = """
114 namespace: org.onap.test
117 app-name: VNF Validation Tool
120 Runs all default validations that apply to all VNF packages
121 regardless of deployment environment
123 polling-freqency: 1000
127 def test_missing_category_fields():
128 settings = yaml.safe_load(StringIO(MISSING_CATEGORY_FIELD))
129 with pytest.raises(RuntimeError) as e:
131 assert "Missing: name" in str(e)
134 def test_default_output_format(config):
135 assert config.default_report_format == "HTML"
138 def test_output_formats(config):
139 for format in ["CSV", "HTML", "Excel"]:
140 assert format in config.report_formats
143 def test_category_names(config):
144 assert "Environment File Compliance. (Required to Onboard)" in config.category_names
147 def test_default_input_format(config):
148 assert "Directory (Uncompressed)" == config.default_input_format
151 def test_input_formats(config):
152 assert "Directory (Uncompressed)" in config.input_formats
153 assert "ZIP File" in config.input_formats
156 def test_env_specs(config):
157 specs = config.env_specs
158 assert len(specs) == 1
159 assert "ALL" in specs[0]
162 def test_get_generator_plugin_names(config):
163 names = get_generator_plugin_names()
164 assert "VNF-API" in names
165 assert "GR-API" in names
168 def test_preload_formats(config):
169 formats = config.preload_formats
170 assert all(format in formats for format in ("VNF-API", "GR-API"))
173 def test_requirement_link_http(config):
174 assert config.requirement_link_url == "http://requirement.url.com"
177 def test_to_uri_relative_path():
178 assert to_uri("path/").startswith("file://")
179 assert to_uri("path/").endswith("/path")
182 def test_to_uri_relative_http():
183 assert to_uri("http://url.com") == "http://url.com"
186 def test_to_uri_absolute_path():
187 assert to_uri("/path/one").startswith("file:///")
188 assert to_uri("/path/one").endswith("/path/one")
191 def test_requirement_link_path(config):
192 config._config["ui"]["requirement-link-url"] = "path/to/reqs.txt"
193 url = config.requirement_link_url
194 assert url.startswith("file://")
195 assert "path/to/reqs.txt" in url
198 def test_terms_version(config):
199 assert config.terms_version == "1.0.0"
202 def test_terms_popup_title(config):
203 assert config.terms_popup_title == "Terms and Conditions"
206 def test_terms_popup_message(config):
207 assert config.terms_popup_message == "Review and Accept the Terms"
210 def test_terms_link_url_default(config):
211 config._config["terms"]["path"] = None
212 assert config.terms_link_url is None
215 def test_terms_acceptance(config):
216 assert not config.are_terms_accepted
217 config.set_terms_accepted()
218 assert config.are_terms_accepted
221 def test_terms_link_url_path(config):
222 assert config.terms_link_url.startswith("file://")
223 assert config.terms_link_url.endswith("/path/to/terms.txt")
226 def test_terms_link_text(config):
227 assert config.terms_link_text == "View Terms and Conditions"
230 def test_default_halt_on_failure(config):
231 assert config.default_halt_on_failure
234 def test_get_subdir_for_preload(config):
235 assert config.get_subdir_for_preload("VNF-API") == "vnfapi"
238 def test_default_preload_format(config):
239 assert config.default_preload_format in ("VNF-API", "GR-API", "Excel")
242 def test_category_description(config):
243 assert "Checks certain parameters" in config.get_description(
244 "Environment File Compliance. (Required to Onboard)"
248 def test_get_category_by_name(config):
250 config.get_category("Environment File Compliance. (Required to Onboard)")
251 == "environment_file"
255 def test_cached_category_setting(config):
257 config.get_category_value("Environment File Compliance. (Required to Onboard)")
262 def test_disclaimer_text(config):
263 assert config.disclaimer_text == ""
266 def test_requirement_link_text(config):
267 url_text = "Requirement URL"
268 config._config["ui"]["requirement-link-text"] = url_text
269 assert config.requirement_link_text == url_text