@@ -237,6 +237,38 @@ def test_cache_key_memcache_validation(self):
237
237
self .assertEqual (cache_key , 'staticfiles:821ea71ef36f95b3922a77f7364670e7' )
238
238
239
239
240
+ @override_settings (
241
+ STATICFILES_STORAGE = 'staticfiles_tests.storage.ExtraPatternsCachedStaticFilesStorage' ,
242
+ )
243
+ class TestExtraPatternsCachedStorage (CollectionTestCase ):
244
+
245
+ def setUp (self ):
246
+ storage .staticfiles_storage .hashed_files .clear () # avoid cache interference
247
+ super (TestExtraPatternsCachedStorage , self ).setUp ()
248
+
249
+ def cached_file_path (self , path ):
250
+ fullpath = self .render_template (self .static_template_snippet (path ))
251
+ return fullpath .replace (settings .STATIC_URL , '' )
252
+
253
+ def test_multi_extension_patterns (self ):
254
+ """
255
+ With storage classes having several file extension patterns, only the
256
+ files matching a specific file pattern should be affected by the
257
+ substitution (#19670).
258
+ """
259
+ # CSS files shouldn't be touched by JS patterns.
260
+ relpath = self .cached_file_path ("cached/import.css" )
261
+ self .assertEqual (relpath , "cached/import.2b1d40b0bbd4.css" )
262
+ with storage .staticfiles_storage .open (relpath ) as relfile :
263
+ self .assertIn (b'import url("styles.bb84a0240107.css")' , relfile .read ())
264
+
265
+ # Confirm JS patterns have been applied to JS files.
266
+ relpath = self .cached_file_path ("cached/test.js" )
267
+ self .assertEqual (relpath , "cached/test.62789ffcd280.js" )
268
+ with storage .staticfiles_storage .open (relpath ) as relfile :
269
+ self .assertIn (b'JS_URL("import.2b1d40b0bbd4.css")' , relfile .read ())
270
+
271
+
240
272
@override_settings (
241
273
STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage' ,
242
274
)
@@ -320,6 +352,10 @@ class TestCollectionSimpleCachedStorage(CollectionTestCase):
320
352
"""
321
353
hashed_file_path = hashed_file_path
322
354
355
+ def setUp (self ):
356
+ storage .staticfiles_storage .hashed_files .clear () # avoid cache interference
357
+ super (TestCollectionSimpleCachedStorage , self ).setUp ()
358
+
323
359
def test_template_tag_return (self ):
324
360
"""
325
361
Test the CachedStaticFilesStorage backend.
0 commit comments