1
1
import os
2
2
3
3
import django
4
- from django .conf import settings
5
- from django .utils import six
6
4
7
- try :
8
- from django .test import override_settings
9
- except ImportError :
10
- # Django < 1.7
11
- from django .test .utils import override_settings
5
+ from django .test import override_settings
12
6
13
7
14
8
def _ (path ):
@@ -24,51 +18,3 @@ def __init__(self, **kwargs):
24
18
# so we must do the same.
25
19
super (pipeline_settings , self ).__init__ ()
26
20
self .options = {'PIPELINE' : kwargs }
27
-
28
-
29
- # Django < 1.7 (copy-pasted from Django 1.7)
30
- class modify_settings (override_settings ):
31
- """
32
- Like override_settings, but makes it possible to append, prepend or remove
33
- items instead of redefining the entire list.
34
- """
35
- def __init__ (self , * args , ** kwargs ):
36
- if args :
37
- # Hack used when instantiating from SimpleTestCase._pre_setup.
38
- assert not kwargs
39
- self .operations = args [0 ]
40
- else :
41
- assert not args
42
- self .operations = list (kwargs .items ())
43
-
44
- def save_options (self , test_func ):
45
- if test_func ._modified_settings is None :
46
- test_func ._modified_settings = self .operations
47
- else :
48
- # Duplicate list to prevent subclasses from altering their parent.
49
- test_func ._modified_settings = list (
50
- test_func ._modified_settings ) + self .operations
51
-
52
- def enable (self ):
53
- self .options = {}
54
- for name , operations in self .operations :
55
- try :
56
- # When called from SimpleTestCase._pre_setup, values may be
57
- # overridden several times; cumulate changes.
58
- value = self .options [name ]
59
- except KeyError :
60
- value = list (getattr (settings , name , []))
61
- for action , items in operations .items ():
62
- # items my be a single value or an iterable.
63
- if isinstance (items , six .string_types ):
64
- items = [items ]
65
- if action == 'append' :
66
- value = value + [item for item in items if item not in value ]
67
- elif action == 'prepend' :
68
- value = [item for item in items if item not in value ] + value
69
- elif action == 'remove' :
70
- value = [item for item in value if item not in items ]
71
- else :
72
- raise ValueError ("Unsupported action: %s" % action )
73
- self .options [name ] = value
74
- super (modify_settings , self ).enable ()
0 commit comments