Commit 65a70b23dbba68e19858d79e5af8821b5d9cc5c3
1 parent
b71fe737
Exists in
master
and in
31 other branches
Test settings validation for db
Showing
7 changed files
with
26 additions
and
61 deletions
Show diff stats
colab/settings.py
colab/utils/conf.py
... | ... | @@ -5,7 +5,6 @@ import importlib |
5 | 5 | import warnings |
6 | 6 | |
7 | 7 | from django.core.exceptions import ImproperlyConfigured |
8 | -from django.utils.translation import ugettext as _ | |
9 | 8 | |
10 | 9 | |
11 | 10 | class InaccessibleSettings(ImproperlyConfigured): |
... | ... | @@ -108,6 +107,6 @@ def load_colab_apps(): |
108 | 107 | def validate_database(database_dict, default_db, debug): |
109 | 108 | db_name = database_dict.get('default', {}).get('NAME') |
110 | 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 | 112 | raise DatabaseUndefined(msg) | ... | ... |
... | ... | @@ -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 | 2 | ## Set to false in production |
3 | -DEBUG = False | |
3 | +DEBUG = True | |
4 | 4 | TEMPLATE_DEBUG = False |
5 | 5 | |
6 | 6 | ## System admins |
... | ... | @@ -25,15 +25,7 @@ ALLOWED_HOSTS = [ |
25 | 25 | ] |
26 | 26 | |
27 | 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 | 30 | ## Disable indexing |
39 | 31 | ROBOTS_NOINDEX = True |
... | ... | @@ -59,3 +51,5 @@ LOGGING = { |
59 | 51 | }, |
60 | 52 | }, |
61 | 53 | } |
54 | + | |
55 | +STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage' | ... | ... |
tests/run.py
... | ... | @@ -3,7 +3,7 @@ |
3 | 3 | import os |
4 | 4 | import sys |
5 | 5 | |
6 | -os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings' | |
6 | +os.environ['DJANGO_SETTINGS_MODULE'] = 'colab.settings' | |
7 | 7 | os.environ['COLAB_SETTINGS'] = 'tests/colab_settings.py' |
8 | 8 | os.environ['COLAB_PLUGINS'] = 'tests/plugins.d' |
9 | 9 | os.environ['COVERAGE_PROCESS_START'] = '.coveragerc' | ... | ... |
tests/settings.py
... | ... | @@ -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 | -} |