Commit 65a70b23dbba68e19858d79e5af8821b5d9cc5c3

Authored by Sergio Oliveira
1 parent b71fe737

Test settings validation for db

colab/settings.py
@@ -59,6 +59,7 @@ INSTALLED_APPS = ( @@ -59,6 +59,7 @@ INSTALLED_APPS = (
59 'colab.rss', 59 'colab.rss',
60 'colab.search', 60 'colab.search',
61 'colab.tz', 61 'colab.tz',
  62 + 'colab.utils',
62 ) 63 )
63 64
64 ROOT_URLCONF = 'colab.urls' 65 ROOT_URLCONF = 'colab.urls'
colab/utils/conf.py
@@ -5,7 +5,6 @@ import importlib @@ -5,7 +5,6 @@ import importlib
5 import warnings 5 import warnings
6 6
7 from django.core.exceptions import ImproperlyConfigured 7 from django.core.exceptions import ImproperlyConfigured
8 -from django.utils.translation import ugettext as _  
9 8
10 9
11 class InaccessibleSettings(ImproperlyConfigured): 10 class InaccessibleSettings(ImproperlyConfigured):
@@ -108,6 +107,6 @@ def load_colab_apps(): @@ -108,6 +107,6 @@ def load_colab_apps():
108 def validate_database(database_dict, default_db, debug): 107 def validate_database(database_dict, default_db, debug):
109 db_name = database_dict.get('default', {}).get('NAME') 108 db_name = database_dict.get('default', {}).get('NAME')
110 if not debug and db_name == default_db: 109 if not debug and db_name == default_db:
111 - msg = _('Since DEBUG is set to False DATABASE must be set on '  
112 - 'colab settings') 110 + msg = ('Since DEBUG is set to False DATABASE must be set on '
  111 + 'Colab settings')
113 raise DatabaseUndefined(msg) 112 raise DatabaseUndefined(msg)
colab/utils/tests/__init__.py 0 → 100644
colab/utils/tests/test_conf.py 0 → 100644
@@ -0,0 +1,18 @@ @@ -0,0 +1,18 @@
  1 +
  2 +from django.test import TestCase, override_settings
  3 +from django.conf import settings
  4 +
  5 +from ..conf import DatabaseUndefined, validate_database
  6 +
  7 +
  8 +class TestConf(TestCase):
  9 +
  10 + @override_settings(DEBUG=False, DATABASES={
  11 + 'default': {
  12 + 'NAME': settings.DEFAULT_DATABASE,
  13 + },
  14 + })
  15 + def test_database_undefined(self):
  16 + with self.assertRaises(DatabaseUndefined):
  17 + validate_database(settings.DATABASES, settings.DEFAULT_DATABASE,
  18 + settings.DEBUG)
tests/colab_settings.py
1 1
2 ## Set to false in production 2 ## Set to false in production
3 -DEBUG = False 3 +DEBUG = True
4 TEMPLATE_DEBUG = False 4 TEMPLATE_DEBUG = False
5 5
6 ## System admins 6 ## System admins
@@ -25,15 +25,7 @@ ALLOWED_HOSTS = [ @@ -25,15 +25,7 @@ ALLOWED_HOSTS = [
25 ] 25 ]
26 26
27 ### Uncomment to enable social networks fields profile 27 ### Uncomment to enable social networks fields profile
28 -# SOCIAL_NETWORK_ENABLED = True  
29 -  
30 -## Database settings  
31 -DATABASES = {  
32 - 'default': {  
33 - 'ENGINE': 'django.db.backends.sqlite3',  
34 - 'NAME': 'colab.sqlite3',  
35 - }  
36 -} 28 +SOCIAL_NETWORK_ENABLED = True
37 29
38 ## Disable indexing 30 ## Disable indexing
39 ROBOTS_NOINDEX = True 31 ROBOTS_NOINDEX = True
@@ -59,3 +51,5 @@ LOGGING = { @@ -59,3 +51,5 @@ LOGGING = {
59 }, 51 },
60 }, 52 },
61 } 53 }
  54 +
  55 +STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage'
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 import os 3 import os
4 import sys 4 import sys
5 5
6 -os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings' 6 +os.environ['DJANGO_SETTINGS_MODULE'] = 'colab.settings'
7 os.environ['COLAB_SETTINGS'] = 'tests/colab_settings.py' 7 os.environ['COLAB_SETTINGS'] = 'tests/colab_settings.py'
8 os.environ['COLAB_PLUGINS'] = 'tests/plugins.d' 8 os.environ['COLAB_PLUGINS'] = 'tests/plugins.d'
9 os.environ['COVERAGE_PROCESS_START'] = '.coveragerc' 9 os.environ['COVERAGE_PROCESS_START'] = '.coveragerc'
tests/settings.py
@@ -1,47 +0,0 @@ @@ -1,47 +0,0 @@
1 -from colab.settings import * # noqa  
2 -  
3 -SOCIAL_NETWORK_ENABLED = True  
4 -STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage'  
5 -  
6 -LOGGING = {  
7 - 'version': 1,  
8 -  
9 - 'handlers': {  
10 - 'null': {  
11 - 'level': 'DEBUG',  
12 - 'class': 'logging.NullHandler',  
13 - },  
14 - },  
15 -  
16 - 'loggers': {  
17 - 'colab.mailman': {  
18 - 'handlers': ['null'],  
19 - 'propagate': False,  
20 - },  
21 - 'haystack': {  
22 - 'handlers': ['null'],  
23 - 'propagate': False,  
24 - },  
25 - 'pysolr': {  
26 - 'handlers': ['null'],  
27 - 'propagate': False,  
28 - },  
29 - },  
30 -}  
31 -  
32 -import os  
33 -HAYSTACK_CONNECTIONS = {  
34 - 'default': {  
35 - 'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine',  
36 - 'PATH': os.path.join(os.path.dirname(__file__), 'whoosh_index'),  
37 - },  
38 -}  
39 -  
40 -SECRET_KEY = 'not-a-secret'  
41 -  
42 -DATABASES = {  
43 - 'default': {  
44 - 'ENGINE': 'django.db.backends.sqlite3',  
45 - 'NAME': 'colab.sqlite',  
46 - }  
47 -}