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
5 # http://www.apache.org/licenses/LICENSE-2.0
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
16 from translator.conf.config import ConfigProvider as translatorConfig
17 from translator.tests.base import TestCase
20 def reload_config(func):
21 '''Decorator to reload config.
23 Set to default values defined in translator.conf file
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)
36 class ConfTest(TestCase):
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)
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')
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')