Update tosca lib to version 0.5
[parser.git] / tosca2heat / heat-translator / translator / tests / test_conf.py
1 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
2 #    not use this file except in compliance with the License. You may obtain
3 #    a copy of the License at
4 #
5 #         http://www.apache.org/licenses/LICENSE-2.0
6 #
7 #    Unless required by applicable law or agreed to in writing, software
8 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 #    License for the specific language governing permissions and limitations
11 #    under the License.
12
13 import mock
14 import os
15
16 from translator.conf.config import ConfigProvider as translatorConfig
17 from translator.tests.base import TestCase
18
19
20 def reload_config(func):
21     '''Decorator to reload config.
22
23     Set to default values defined in translator.conf file
24
25     '''
26
27     def reload(*args):
28         func(*args)
29         path = os.path.dirname(os.path.abspath(__file__)) + '/../conf/'
30         conf_file = os.path.join(path, 'translator.conf')
31         translatorConfig._load_config(conf_file)
32
33     return reload
34
35
36 class ConfTest(TestCase):
37
38     @reload_config
39     @mock.patch('six.moves.configparser.ConfigParser')
40     def test_load_config(self, mock_config_parser):
41         translatorConfig._translator_config.read = mock.MagicMock()
42         translatorConfig._load_config('fake_file.conf')
43         self.assertTrue(translatorConfig._translator_config.read.called)
44
45     def test_get_value(self):
46         ret_value = mock.MagicMock(return_value='hot')
47         translatorConfig._translator_config.get = ret_value
48         value = translatorConfig.get_value('DEFAULT', 'language')
49         self.assertTrue(translatorConfig._translator_config.get.called)
50         self.assertEqual(value, 'hot')
51
52     def test_get_all_values(self):
53         ret_value = mock.MagicMock(return_value=['hot'])
54         translatorConfig._translator_config.items = ret_value
55         values = translatorConfig.get_all_values()
56         self.assertTrue(translatorConfig._translator_config.items.called)
57         self.assertEqual(values[0], 'hot')