1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
22 common.CONF_FILE = None
23 common.DEPLOYMENT_UNIT = None
24 common.ITERATIONS = None
25 common.BASE_DIR = None
26 common.TEMPLATE_DIR = None
27 common.TEMPLATE_NAME = None
28 common.TEMPLATE_EXTENSION = None
31 class TestGeneratesTemplate(unittest.TestCase):
34 self.deployment_configuration = {
37 self.template_name = 'rubbos_1-1-1_template.tmp'
43 @mock.patch('common.LOG')
44 @mock.patch('common.get_template_dir')
45 def test_generates_template_for_success(self, mock_template_dir,
47 tmp_generated_templates_dir = '/data/generated_templates/'
48 generated_templates_dir = "{}{}".format(
49 os.getcwd(), tmp_generated_templates_dir)
50 mock_template_dir.return_value = generated_templates_dir
51 tmp_test_templates = '/data/test_templates/'
52 test_templates = "{}{}".format(os.getcwd(), tmp_test_templates)
53 template.generates_templates(self.template_name,
54 self.deployment_configuration)
55 for dirname, dirnames, filenames in os.walk(test_templates):
56 for filename in filenames:
57 with open(test_templates + filename) as test:
58 with open(generated_templates_dir + filename) as generated:
59 self.assertListEqual(test.readlines(),
60 generated.readlines())
62 t_name = '/data/generated_templates/rubbos_1-1-1_template.tmp'
63 self.template_name = "{}{}".format(os.getcwd(), t_name)
64 template.generates_templates(self.template_name,
65 self.deployment_configuration)
66 for dirname, dirnames, filenames in os.walk(test_templates):
67 for filename in filenames:
68 with open(test_templates + filename) as test:
69 with open(generated_templates_dir + filename) as generated:
70 self.assertListEqual(test.readlines(),
71 generated.readlines())
73 @mock.patch('common.get_template_dir')
74 def test_get_all_heat_templates_for_success(self, template_dir):
75 tmp_generated_templates = '/data/generated_templates/'
76 generated_templates = "{}{}".format(
77 os.getcwd(), tmp_generated_templates)
78 template_dir.return_value = generated_templates
80 expected = ['test_template_1.yaml']
81 result = template.get_all_heat_templates(generated_templates,
83 self.assertListEqual(expected, result)