Skip to content

Commit

Permalink
Merge pull request #165 from colab/fix_settings_d_test_issue
Browse files Browse the repository at this point in the history
Fixing local settings.d import on tests
  • Loading branch information
GustJc committed Mar 24, 2016
2 parents e55b356 + 8c6d5fd commit 3280716
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions colab/utils/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
2 changes: 0 additions & 2 deletions colab/utils/tests/settings.d/test.py

This file was deleted.

12 changes: 10 additions & 2 deletions colab/utils/tests/test_conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys
import os

from django.test import TestCase, override_settings, Client
from django.conf import settings
Expand Down Expand Up @@ -49,8 +50,12 @@ 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):
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)
Expand All @@ -59,6 +64,9 @@ def test_load_py_settings_without_settings_d(self, mock):
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',
Expand Down
1 change: 1 addition & 0 deletions tests/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Empty file added tests/settings.d/settings.py
Empty file.

0 comments on commit 3280716

Please sign in to comment.