69709afde09b1aea0dfe055404ebaa8690de4fee
[vvp/validation-scripts.git] / ice_validator / tests / conftest.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 import os
42
43
44 __path__ = [os.path.dirname(os.path.abspath(__file__))]
45
46
47 def pytest_addoption(parser):
48     """
49     Add needed CLI arguments
50     """
51     parser.addoption("--template-directory",
52                      dest="template_dir",
53                      action="append",
54                      help="Directory which holds the templates for validation")
55
56     parser.addoption("--self-test",
57                      dest="self_test",
58                      action='store_true',
59                      help="Test the unit tests against their fixtured data")
60
61
62 def pytest_configure(config):
63     """
64     Ensure that we are receive either `--self-test` or
65     `--template-dir=<directory` as CLI arguments
66     """
67     if config.getoption('template_dir') and config.getoption('self_test'):
68         raise Exception(('"--template-dir", and "--self-test"'
69                         ' are mutually exclusive'))
70     if not (config.getoption('template_dir') or config.getoption('self_test')):
71         raise Exception(('One of "--template-dir" or'
72                         ' "--self-test" must be specified'))
73
74
75 def pytest_generate_tests(metafunc):
76     """
77     If a unit test requires an argument named 'filename'
78     we generate a test for the filenames selected. Either
79     the files contained in `template_dir` or if `template_dir`
80     is not specified on the CLI, the fixtures associated with this
81     test name.
82     """
83     if 'filename' in metafunc.fixturenames:
84         from .parametrizers import parametrize_filename
85         parametrize_filename(metafunc)
86
87     if 'filenames' in metafunc.fixturenames:
88         from .parametrizers import parametrize_filenames
89         parametrize_filenames(metafunc)
90
91     if 'template_dir' in metafunc.fixturenames:
92         from .parametrizers import parametrize_template_dir
93         parametrize_template_dir(metafunc)
94
95     if 'environment_pair' in metafunc.fixturenames:
96         from .parametrizers import parametrize_environment_pair
97         parametrize_environment_pair(metafunc)
98
99     if 'heat_volume_pair' in metafunc.fixturenames:
100         from .parametrizers import parametrize_heat_volume_pair
101         parametrize_heat_volume_pair(metafunc)
102
103     if 'yaml_files' in metafunc.fixturenames:
104         from .parametrizers import parametrize_yaml_files
105         parametrize_yaml_files(metafunc)
106
107     if 'env_files' in metafunc.fixturenames:
108         from .parametrizers import parametrize_environment_files
109         parametrize_environment_files(metafunc)
110
111     if 'yaml_file' in metafunc.fixturenames:
112         from .parametrizers import parametrize_yaml_file
113         parametrize_yaml_file(metafunc)
114
115     if 'env_file' in metafunc.fixturenames:
116         from .parametrizers import parametrize_environment_file
117         parametrize_environment_file(metafunc)
118
119     if 'parsed_yaml_file' in metafunc.fixturenames:
120         from .parametrizers import parametrize_parsed_yaml_file
121         parametrize_parsed_yaml_file(metafunc)
122
123     if 'parsed_environment_file' in metafunc.fixturenames:
124         from .parametrizers import parametrize_parsed_environment_file
125         parametrize_parsed_environment_file(metafunc)
126
127     if 'heat_template' in metafunc.fixturenames:
128         from .parametrizers import parametrize_heat_template
129         parametrize_heat_template(metafunc)
130
131     if 'heat_templates' in metafunc.fixturenames:
132         from .parametrizers import parametrize_heat_templates
133         parametrize_heat_templates(metafunc)
134
135     if 'volume_template' in metafunc.fixturenames:
136         from .parametrizers import parametrize_volume_template
137         parametrize_volume_template(metafunc)
138
139     if 'volume_templates' in metafunc.fixturenames:
140         from .parametrizers import parametrize_volume_templates
141         parametrize_volume_templates(metafunc)
142
143     if 'template' in metafunc.fixturenames:
144         from .parametrizers import parametrize_template
145         parametrize_template(metafunc)
146
147     if 'templates' in metafunc.fixturenames:
148         from .parametrizers import parametrize_templates
149         parametrize_templates(metafunc)