1
1
from __future__ import unicode_literals
2
2
3
+ from django .contrib .staticfiles .storage import staticfiles_storage
4
+ from django .core .management import call_command
3
5
from django .test import TestCase
6
+ from django .test .utils import override_settings
4
7
5
8
from pipeline .storage import PipelineStorage
6
9
10
+ from tests .tests .test_compiler import DummyCompiler
7
11
from tests .utils import pipeline_settings
8
12
13
+ try :
14
+ from io import StringIO
15
+ except ImportError :
16
+ from StringIO import StringIO
17
+
18
+
19
+ class PipelineNoPathStorage (PipelineStorage ):
20
+ """Storage without an implemented path method"""
21
+ def path (self , * args ):
22
+ raise NotImplementedError ()
23
+
24
+ def delete (self , * args ):
25
+ return
26
+
27
+ def exists (self , * args ):
28
+ return True
29
+
30
+ def save (self , * args ):
31
+ return
32
+
33
+ def open (self , * args ):
34
+ return StringIO ()
35
+
36
+
37
+ class DummyCSSCompiler (DummyCompiler ):
38
+ """ Handles css files """
39
+ output_extension = 'css'
40
+
41
+ def match_file (self , path ):
42
+ return path .endswith ('.css' )
43
+
9
44
10
45
class StorageTest (TestCase ):
46
+ def tearDown (self ):
47
+ staticfiles_storage ._setup ()
48
+
11
49
def test_post_process_dry_run (self ):
12
50
with pipeline_settings (PIPELINE_JS_COMPRESSOR = None , PIPELINE_CSS_COMPRESSOR = None ):
13
51
processed_files = PipelineStorage ().post_process ({}, True )
@@ -19,3 +57,15 @@ def test_post_process(self):
19
57
processed_files = storage .post_process ({})
20
58
self .assertTrue (('screen.css' , 'screen.css' , True ) in processed_files )
21
59
self .assertTrue (('scripts.js' , 'scripts.js' , True ) in processed_files )
60
+
61
+ def test_post_process_no_path (self ):
62
+ """
63
+ Test post_process with a storage that doesn't implement the path method.
64
+ """
65
+ with override_settings (STATICFILES_STORAGE = 'tests.tests.test_storage.PipelineNoPathStorage' , PIPELINE_COMPILERS = ['tests.tests.test_storage.DummyCSSCompiler' ]):
66
+ with pipeline_settings (PIPELINE_JS_COMPRESSOR = None , PIPELINE_CSS_COMPRESSOR = None ):
67
+ staticfiles_storage ._setup ()
68
+ try :
69
+ call_command ('collectstatic' , verbosity = 0 , interactive = False )
70
+ except NotImplementedError :
71
+ self .fail ('Received an error running collectstatic' )
0 commit comments