47bb7257d27cf4243d293c834175b21a13c01197
[vvp/validation-scripts.git] / ice_validator / app_tests / test_app_config.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 # ECOMP is a trademark and service mark of AT&T Intellectual Property.
39 #
40
41 from io import StringIO
42
43 import pytest
44 import yaml
45
46 import vvp
47
48 DEFAULT_CONFIG = """
49 ui:
50   app-name: VNF Validation Tool
51 categories:
52   - name: Environment File Compliance. (Required to Onboard)
53     category: environment_file
54     description:
55       Checks certain parameters are excluded from the .env file, per HOT Requirements.
56       Required for ASDC onboarding, not needed for manual Openstack testing.
57 settings:
58   polling-freqency: 1000
59   default-verbosity: Standard
60 """
61
62
63 # noinspection PyShadowingNames
64 @pytest.fixture(scope="module")
65 def config():
66     return vvp.Config(yaml.load(StringIO(DEFAULT_CONFIG)))
67
68
69 def test_app_name(config):
70     assert "VNF Validation Tool" in config.app_name
71     assert vvp.VERSION in config.app_name
72
73
74 def test_categories_names_length(config):
75     names = config.category_names
76     assert len(names) == 1
77     assert names[0] == "Environment File Compliance. (Required to Onboard)"
78
79
80 def test_polling_frequency(config):
81     assert config.polling_frequency == 1000
82
83
84 def test_get_category_when_other(config):
85     assert (
86         config.get_category("Environment File Compliance. (Required to Onboard)")
87         == "environment_file"
88     )
89
90
91 def test_default_verbosity(config):
92     assert config.default_verbosity(vvp.ValidatorApp.VERBOSITY_LEVELS) == "Standard (-v)"
93
94
95 def test_queues(config):
96     assert config.log_queue.empty(), "Log should start empty"
97     config.log_file.write("Test")
98     assert config.log_queue.get() == "Test"
99
100     assert config.status_queue.empty(), "status should start empty"
101     config.status_queue.put((True, None))
102     assert config.status_queue.get() == (True, None)
103
104
105 MISSING_CATEGORY_FIELD = """
106 ui:
107   app-name: VNF Validation Tool
108 categories:
109   - description: |
110       Runs all default validations that apply to all VNF packages
111       regardless of deployment environment
112 settings:
113   polling-freqency: 1000
114 """
115
116
117 def test_missing_category_fields():
118     settings = yaml.load(StringIO(MISSING_CATEGORY_FIELD))
119     with pytest.raises(RuntimeError) as e:
120         vvp.Config(settings)
121     assert "Missing: name" in str(e)
122
123
124 def test_default_output_format(config):
125     assert config.default_report_format == "HTML"
126
127
128 def test_output_formats(config):
129     for format in ["CSV", "HTML", "Excel"]:
130         assert format in config.report_formats
131
132
133 def test_category_names(config):
134     assert "Environment File Compliance. (Required to Onboard)" in config.category_names
135
136
137 def test_default_input_format(config):
138     assert "Directory (Uncompressed)" == config.default_input_format
139
140
141 def test_input_formats(config):
142     assert "Directory (Uncompressed)" in config.input_formats
143     assert "ZIP File" in config.input_formats