@@ -23,27 +23,29 @@ class AppSettings(object):
23
23
"""
24
24
Class to manage application related settings
25
25
How to use:
26
-
26
+ >>> import pytest
27
27
>>> from django.conf import settings
28
+ >>> from concurrency.utils import fqn
28
29
>>> settings.APP_OVERRIDE = 'overridden'
29
- >>> settings.MYAPP_CALLBACK = 100
30
30
>>> class MySettings(AppSettings):
31
- ... defaults = {'ENTRY1': 'abc', 'ENTRY2': 123, 'OVERRIDE': None, 'CALLBACK':10}
32
- ... def set_CALLBACK(self, value):
33
- ... setattr(self, 'CALLBACK', value*2)
31
+ ... defaults = {'ENTRY1': 'abc', 'ENTRY2': 123, 'OVERRIDE': None, 'CALLBACK': fqn(fqn)}
34
32
35
33
>>> conf = MySettings("APP")
36
- >>> conf.ENTRY1, settings.APP_ENTRY1
34
+ >>> str( conf.ENTRY1), str( settings.APP_ENTRY1)
37
35
('abc', 'abc')
38
- >>> conf.OVERRIDE, settings.APP_OVERRIDE
36
+ >>> str( conf.OVERRIDE), str( settings.APP_OVERRIDE)
39
37
('overridden', 'overridden')
40
38
41
39
>>> conf = MySettings("MYAPP")
42
40
>>> conf.ENTRY2, settings.MYAPP_ENTRY2
43
41
(123, 123)
42
+ >>> settings.MYAPP_CALLBACK = fqn
44
43
>>> conf = MySettings("MYAPP")
45
- >>> conf.CALLBACK
46
- 200
44
+ >>> conf.CALLBACK == fqn
45
+ True
46
+ >>> with pytest.raises(ImproperlyConfigured):
47
+ ... settings.OTHER_CALLBACK = 222
48
+ ... conf = MySettings("OTHER")
47
49
48
50
"""
49
51
defaults = {
@@ -81,7 +83,7 @@ def _set_attr(self, prefix_name, value):
81
83
elif callable (value ):
82
84
func = value
83
85
else :
84
- raise ImproperlyConfigured ("`CALLBACK` must be a callable or a fullpath to callable" )
86
+ raise ImproperlyConfigured ("{} is not a valid value for `CALLBACK`. It must be a callable or a fullpath to callable. " . format ( value ) )
85
87
self ._callback = func
86
88
87
89
setattr (self , name , value )
0 commit comments