Commit 9b3cca5be26429917f3b48af764dff0436264b02

Authored by Lucas Moura
1 parent 33e56fbc

Changed load_settings to receive any settings_dir

Signed-off-by: Lucas Moura <lucas.moura128@gmail.com>
Signed-off-by: Tomaz Martins <tomaz.r.martins@gmail.com>
colab/utils/conf.py
@@ -54,7 +54,7 @@ def _load_py_file(py_path, path): @@ -54,7 +54,7 @@ def _load_py_file(py_path, path):
54 return py_setting 54 return py_setting
55 55
56 56
57 -def load_py_settings(): 57 +def load_py_settings(settings_dir='/etc/colab/settings.d'):
58 settings_file = os.getenv('COLAB_SETTINGS', '/etc/colab/settings.py') 58 settings_file = os.getenv('COLAB_SETTINGS', '/etc/colab/settings.py')
59 settings_module = settings_file.split('.')[-2].split('/')[-1] 59 settings_module = settings_file.split('.')[-2].split('/')[-1]
60 py_path = "/".join(settings_file.split('/')[:-1]) 60 py_path = "/".join(settings_file.split('/')[:-1])
@@ -67,8 +67,6 @@ def load_py_settings(): @@ -67,8 +67,6 @@ def load_py_settings():
67 67
68 py_settings = _load_py_file(settings_module, py_path) 68 py_settings = _load_py_file(settings_module, py_path)
69 69
70 - # Read settings from settings.d  
71 - settings_dir = '/etc/colab/settings.d'  
72 logger.info('Settings directory: %s', settings_dir) 70 logger.info('Settings directory: %s', settings_dir)
73 71
74 if not os.path.exists(settings_dir): 72 if not os.path.exists(settings_dir):
colab/utils/tests/test_conf.py
@@ -43,9 +43,9 @@ class TestConf(TestCase): @@ -43,9 +43,9 @@ class TestConf(TestCase):
43 def test_load_py_settings_with_inaccessible_settings(self, mock): 43 def test_load_py_settings_with_inaccessible_settings(self, mock):
44 self.assertRaises(InaccessibleSettings, load_py_settings) 44 self.assertRaises(InaccessibleSettings, load_py_settings)
45 45
46 - @patch('os.path.exists', side_effect=[True, False]) 46 + @patch('os.getenv', return_value='./tests/colab_settings.py')
47 def test_load_py_settings_without_settings_d(self, mock): 47 def test_load_py_settings_without_settings_d(self, mock):
48 - py_settings = load_py_settings() 48 + py_settings = load_py_settings('/path/fake/settings.d/test.py')
49 49
50 self.assertIn('SOCIAL_NETWORK_ENABLED', py_settings) 50 self.assertIn('SOCIAL_NETWORK_ENABLED', py_settings)
51 self.assertTrue(py_settings['SOCIAL_NETWORK_ENABLED']) 51 self.assertTrue(py_settings['SOCIAL_NETWORK_ENABLED'])
@@ -59,7 +59,7 @@ class TestConf(TestCase): @@ -59,7 +59,7 @@ class TestConf(TestCase):
59 side_effect=[{'SOCIAL_NETWORK_ENABLED': True, 'EMAIL_PORT': 25}, 59 side_effect=[{'SOCIAL_NETWORK_ENABLED': True, 'EMAIL_PORT': 25},
60 {'TEST': 'test'}]) 60 {'TEST': 'test'}])
61 def test_load_py_settings_with_settings_d(self, mock_py, mock_listdir): 61 def test_load_py_settings_with_settings_d(self, mock_py, mock_listdir):
62 - py_settings = load_py_settings() 62 + py_settings = load_py_settings('./tests/settings.d/')
63 63
64 self.assertIn('SOCIAL_NETWORK_ENABLED', py_settings) 64 self.assertIn('SOCIAL_NETWORK_ENABLED', py_settings)
65 self.assertTrue(py_settings['SOCIAL_NETWORK_ENABLED']) 65 self.assertTrue(py_settings['SOCIAL_NETWORK_ENABLED'])