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 ##############################################################################
21 common.CONF_FILE = None
22 common.DEPLOYMENT_UNIT = None
23 common.ITERATIONS = None
24 common.BASE_DIR = None
25 common.TEMPLATE_DIR = None
26 common.TEMPLATE_NAME = None
27 common.TEMPLATE_EXTENSION = None
29 class TestGeneratesTemplate(unittest.TestCase):
31 self.deployment_configuration = {
34 self.template_name = 'rubbos_1-1-1_template.tmp'
40 @mock.patch('common.LOG')
41 @mock.patch('common.get_template_dir')
42 def test_generates_template_for_success(self, mock_template_dir,
44 tmp_generated_templates_dir = '/data/generated_templates/'
45 generated_templates_dir = "{}{}".format(os.getcwd(), tmp_generated_templates_dir)
46 mock_template_dir.return_value = generated_templates_dir
47 tmp_test_templates = '/data/test_templates/'
48 test_templates = "{}{}".format(os.getcwd(), tmp_test_templates)
49 template.generates_templates(self.template_name,
50 self.deployment_configuration)
51 for dirname, dirnames, filenames in os.walk(test_templates):
52 for filename in filenames:
53 with open(test_templates + filename) as test:
54 with open(generated_templates_dir + filename) as generated:
55 self.assertListEqual(test.readlines(),
56 generated.readlines())
58 t_name = '/data/generated_templates/rubbos_1-1-1_template.tmp'
59 self.template_name = "{}{}".format(os.getcwd(), t_name)
60 template.generates_templates(self.template_name,
61 self.deployment_configuration)
62 for dirname, dirnames, filenames in os.walk(test_templates):
63 for filename in filenames:
64 with open(test_templates + filename) as test:
65 with open(generated_templates_dir + filename) as generated:
66 self.assertListEqual(test.readlines(),
67 generated.readlines())
69 @mock.patch('common.get_template_dir')
70 def test_get_all_heat_templates_for_success(self, template_dir):
71 tmp_generated_templates = '/data/generated_templates/'
72 generated_templates = "{}{}".format(os.getcwd(), tmp_generated_templates)
73 template_dir.return_value = generated_templates
75 expected = ['test_template_1.yaml']
76 result = template.get_all_heat_templates(generated_templates,
78 self.assertListEqual(expected, result)