1 # Copyright (c) 2015 Intel Research and Development Ireland Ltd.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
16 import experimental_framework.heat_template_generation as heat_gen
19 import experimental_framework.common as common
22 class TestGeneratesTemplate(unittest.TestCase):
24 self.deployment_configuration = {
25 'vnic_type': ['normal', 'direct'],
29 self.template_name = 'VTC_base_single_vm_wait.tmp'
38 @mock.patch('experimental_framework.common.get_template_dir')
39 def test_generates_template_for_success(self, mock_template_dir):
40 generated_templates_dir = 'tests/data/generated_templates/'
41 mock_template_dir.return_value = generated_templates_dir
42 test_templates = 'tests/data/test_templates/'
43 heat_gen.generates_templates(self.template_name,
44 self.deployment_configuration)
45 for dirname, dirnames, filenames in os.walk(test_templates):
46 for filename in filenames:
47 with open(test_templates + filename) as test:
48 with open(generated_templates_dir + filename) as generated:
49 self.assertListEqual(test.readlines(),
50 generated.readlines())
52 t_name = '/tests/data/generated_templates/VTC_base_single_vm_wait.tmp'
53 self.template_name = os.getcwd() + t_name
54 heat_gen.generates_templates(self.template_name,
55 self.deployment_configuration)
56 for dirname, dirnames, filenames in os.walk(test_templates):
57 for filename in filenames:
58 with open(test_templates + filename) as test:
59 with open(generated_templates_dir + filename) as generated:
60 self.assertListEqual(test.readlines(),
61 generated.readlines())
63 @mock.patch('experimental_framework.common.get_template_dir')
64 def test_get_all_heat_templates_for_success(self, template_dir):
65 generated_templates = 'tests/data/generated_templates/'
66 template_dir.return_value = generated_templates
68 expected = ['experiment_1.yaml', 'experiment_2.yaml']
69 result = heat_gen.get_all_heat_templates(generated_templates,
71 self.assertListEqual(expected, result)