From 7794cccb46cad2313261ac9280dd629a1fa81879 Mon Sep 17 00:00:00 2001 From: Matheus Faria Date: Mon, 21 Mar 2016 17:44:19 -0300 Subject: [PATCH 1/2] Fixing local settings.d import on tests --- colab/utils/conf.py | 1 + colab/utils/tests/test_conf.py | 3 +-- tests/run.py | 1 + tests/settings.d/settings.py | 0 4 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 tests/settings.d/settings.py diff --git a/colab/utils/conf.py b/colab/utils/conf.py index f103217b..6e7f0e7b 100644 --- a/colab/utils/conf.py +++ b/colab/utils/conf.py @@ -55,6 +55,7 @@ def _load_py_file(py_path, path): def load_py_settings(settings_dir='/etc/colab/settings.d'): + settings_dir = os.getenv('COLAB_SETTINGS_DIR', settings_dir) settings_file = os.getenv('COLAB_SETTINGS', '/etc/colab/settings.py') settings_module = settings_file.split('.')[-2].split('/')[-1] py_path = "/".join(settings_file.split('/')[:-1]) diff --git a/colab/utils/tests/test_conf.py b/colab/utils/tests/test_conf.py index 4d424ec8..dc490790 100644 --- a/colab/utils/tests/test_conf.py +++ b/colab/utils/tests/test_conf.py @@ -49,8 +49,7 @@ def test_load_py_file(self): def test_load_py_settings_with_inaccessible_settings(self, mock): self.assertRaises(InaccessibleSettings, load_py_settings) - @patch('os.getenv', return_value=test_files_dir + '/colab_settings.py') - def test_load_py_settings_without_settings_d(self, mock): + def test_load_py_settings_without_settings_d(self): py_settings = load_py_settings('/path/fake/settings.d/test.py') self.assertIn('SOCIAL_NETWORK_ENABLED', py_settings) diff --git a/tests/run.py b/tests/run.py index 4c3d590e..efd73164 100755 --- a/tests/run.py +++ b/tests/run.py @@ -5,6 +5,7 @@ os.environ['DJANGO_SETTINGS_MODULE'] = 'colab.settings' os.environ['COLAB_SETTINGS'] = 'tests/colab_settings.py' +os.environ['COLAB_SETTINGS_DIR'] = 'tests/settings.d' os.environ['COLAB_WIDGETS_SETTINGS'] = 'tests/widgets_settings.py' os.environ['COLAB_PLUGINS'] = 'tests/plugins.d' os.environ['COLAB_WIDGETS'] = 'tests/widgets.d' diff --git a/tests/settings.d/settings.py b/tests/settings.d/settings.py new file mode 100644 index 00000000..e69de29b From 8c6d5fd0ecfb975738992e73263187219715c068 Mon Sep 17 00:00:00 2001 From: Matheus Faria Date: Wed, 23 Mar 2016 15:14:47 -0300 Subject: [PATCH 2/2] Testing util.conf without settings.d directory --- colab/utils/tests/settings.d/test.py | 2 -- colab/utils/tests/test_conf.py | 9 +++++++++ 2 files changed, 9 insertions(+), 2 deletions(-) delete mode 100644 colab/utils/tests/settings.d/test.py diff --git a/colab/utils/tests/settings.d/test.py b/colab/utils/tests/settings.d/test.py deleted file mode 100644 index f75909b5..00000000 --- a/colab/utils/tests/settings.d/test.py +++ /dev/null @@ -1,2 +0,0 @@ -RIBBON_ENABLED = False -TEST = 'test' diff --git a/colab/utils/tests/test_conf.py b/colab/utils/tests/test_conf.py index dc490790..62c1123f 100644 --- a/colab/utils/tests/test_conf.py +++ b/colab/utils/tests/test_conf.py @@ -1,4 +1,5 @@ import sys +import os from django.test import TestCase, override_settings, Client from django.conf import settings @@ -50,6 +51,11 @@ def test_load_py_settings_with_inaccessible_settings(self, mock): self.assertRaises(InaccessibleSettings, load_py_settings) def test_load_py_settings_without_settings_d(self): + COLAB_SETTINGS_DIR = '' + if 'COLAB_SETTINGS_DIR' in os.environ: + COLAB_SETTINGS_DIR = os.environ['COLAB_SETTINGS_DIR'] + del os.environ['COLAB_SETTINGS_DIR'] + py_settings = load_py_settings('/path/fake/settings.d/test.py') self.assertIn('SOCIAL_NETWORK_ENABLED', py_settings) @@ -58,6 +64,9 @@ def test_load_py_settings_without_settings_d(self): self.assertIn('EMAIL_PORT', py_settings) self.assertEquals(py_settings['EMAIL_PORT'], 25) + if COLAB_SETTINGS_DIR: + os.environ['COLAB_SETTINGS_DIR'] = COLAB_SETTINGS_DIR + @patch('os.listdir', return_value=[test_files_dir + '/settings.d/test.py', 'non_python_file']) @patch('colab.utils.conf._load_py_file',