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