From 65a70b23dbba68e19858d79e5af8821b5d9cc5c3 Mon Sep 17 00:00:00 2001 From: Sergio Oliveira Date: Tue, 28 Jul 2015 12:37:31 -0300 Subject: [PATCH] Test settings validation for db --- colab/settings.py | 1 + colab/utils/conf.py | 5 ++--- colab/utils/tests/__init__.py | 0 colab/utils/tests/test_conf.py | 18 ++++++++++++++++++ tests/colab_settings.py | 14 ++++---------- tests/run.py | 2 +- tests/settings.py | 47 ----------------------------------------------- 7 files changed, 26 insertions(+), 61 deletions(-) create mode 100644 colab/utils/tests/__init__.py create mode 100644 colab/utils/tests/test_conf.py delete mode 100644 tests/settings.py diff --git a/colab/settings.py b/colab/settings.py index 937487e..b4d7f3b 100644 --- a/colab/settings.py +++ b/colab/settings.py @@ -59,6 +59,7 @@ INSTALLED_APPS = ( 'colab.rss', 'colab.search', 'colab.tz', + 'colab.utils', ) ROOT_URLCONF = 'colab.urls' diff --git a/colab/utils/conf.py b/colab/utils/conf.py index 5df2338..8367005 100644 --- a/colab/utils/conf.py +++ b/colab/utils/conf.py @@ -5,7 +5,6 @@ import importlib import warnings from django.core.exceptions import ImproperlyConfigured -from django.utils.translation import ugettext as _ class InaccessibleSettings(ImproperlyConfigured): @@ -108,6 +107,6 @@ def load_colab_apps(): def validate_database(database_dict, default_db, debug): db_name = database_dict.get('default', {}).get('NAME') if not debug and db_name == default_db: - msg = _('Since DEBUG is set to False DATABASE must be set on ' - 'colab settings') + msg = ('Since DEBUG is set to False DATABASE must be set on ' + 'Colab settings') raise DatabaseUndefined(msg) diff --git a/colab/utils/tests/__init__.py b/colab/utils/tests/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/colab/utils/tests/__init__.py diff --git a/colab/utils/tests/test_conf.py b/colab/utils/tests/test_conf.py new file mode 100644 index 0000000..076e908 --- /dev/null +++ b/colab/utils/tests/test_conf.py @@ -0,0 +1,18 @@ + +from django.test import TestCase, override_settings +from django.conf import settings + +from ..conf import DatabaseUndefined, validate_database + + +class TestConf(TestCase): + + @override_settings(DEBUG=False, DATABASES={ + 'default': { + 'NAME': settings.DEFAULT_DATABASE, + }, + }) + def test_database_undefined(self): + with self.assertRaises(DatabaseUndefined): + validate_database(settings.DATABASES, settings.DEFAULT_DATABASE, + settings.DEBUG) diff --git a/tests/colab_settings.py b/tests/colab_settings.py index c9b1b9a..bf1efa5 100644 --- a/tests/colab_settings.py +++ b/tests/colab_settings.py @@ -1,6 +1,6 @@ ## Set to false in production -DEBUG = False +DEBUG = True TEMPLATE_DEBUG = False ## System admins @@ -25,15 +25,7 @@ ALLOWED_HOSTS = [ ] ### Uncomment to enable social networks fields profile -# SOCIAL_NETWORK_ENABLED = True - -## Database settings -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': 'colab.sqlite3', - } -} +SOCIAL_NETWORK_ENABLED = True ## Disable indexing ROBOTS_NOINDEX = True @@ -59,3 +51,5 @@ LOGGING = { }, }, } + +STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage' diff --git a/tests/run.py b/tests/run.py index c73b478..3e7ab18 100755 --- a/tests/run.py +++ b/tests/run.py @@ -3,7 +3,7 @@ import os import sys -os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings' +os.environ['DJANGO_SETTINGS_MODULE'] = 'colab.settings' os.environ['COLAB_SETTINGS'] = 'tests/colab_settings.py' os.environ['COLAB_PLUGINS'] = 'tests/plugins.d' os.environ['COVERAGE_PROCESS_START'] = '.coveragerc' diff --git a/tests/settings.py b/tests/settings.py deleted file mode 100644 index c93892c..0000000 --- a/tests/settings.py +++ /dev/null @@ -1,47 +0,0 @@ -from colab.settings import * # noqa - -SOCIAL_NETWORK_ENABLED = True -STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage' - -LOGGING = { - 'version': 1, - - 'handlers': { - 'null': { - 'level': 'DEBUG', - 'class': 'logging.NullHandler', - }, - }, - - 'loggers': { - 'colab.mailman': { - 'handlers': ['null'], - 'propagate': False, - }, - 'haystack': { - 'handlers': ['null'], - 'propagate': False, - }, - 'pysolr': { - 'handlers': ['null'], - 'propagate': False, - }, - }, -} - -import os -HAYSTACK_CONNECTIONS = { - 'default': { - 'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine', - 'PATH': os.path.join(os.path.dirname(__file__), 'whoosh_index'), - }, -} - -SECRET_KEY = 'not-a-secret' - -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': 'colab.sqlite', - } -} -- libgit2 0.21.2