diff options
Diffstat (limited to 'tests/staticfiles_tests/test_storage.py')
| -rw-r--r-- | tests/staticfiles_tests/test_storage.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/staticfiles_tests/test_storage.py b/tests/staticfiles_tests/test_storage.py index bd636c4a8c..318b26c635 100644 --- a/tests/staticfiles_tests/test_storage.py +++ b/tests/staticfiles_tests/test_storage.py @@ -238,6 +238,38 @@ class TestCollectionCachedStorage(TestHashedFiles, CollectionTestCase): @override_settings( + STATICFILES_STORAGE='staticfiles_tests.storage.ExtraPatternsCachedStaticFilesStorage', +) +class TestExtraPatternsCachedStorage(CollectionTestCase): + + def setUp(self): + storage.staticfiles_storage.hashed_files.clear() # avoid cache interference + super(TestExtraPatternsCachedStorage, self).setUp() + + def cached_file_path(self, path): + fullpath = self.render_template(self.static_template_snippet(path)) + return fullpath.replace(settings.STATIC_URL, '') + + def test_multi_extension_patterns(self): + """ + With storage classes having several file extension patterns, only the + files matching a specific file pattern should be affected by the + substitution (#19670). + """ + # CSS files shouldn't be touched by JS patterns. + relpath = self.cached_file_path("cached/import.css") + self.assertEqual(relpath, "cached/import.2b1d40b0bbd4.css") + with storage.staticfiles_storage.open(relpath) as relfile: + self.assertIn(b'import url("styles.bb84a0240107.css")', relfile.read()) + + # Confirm JS patterns have been applied to JS files. + relpath = self.cached_file_path("cached/test.js") + self.assertEqual(relpath, "cached/test.62789ffcd280.js") + with storage.staticfiles_storage.open(relpath) as relfile: + self.assertIn(b'JS_URL("import.2b1d40b0bbd4.css")', relfile.read()) + + +@override_settings( STATICFILES_STORAGE='django.contrib.staticfiles.storage.ManifestStaticFilesStorage', ) class TestCollectionManifestStorage(TestHashedFiles, CollectionTestCase): @@ -320,6 +352,10 @@ class TestCollectionSimpleCachedStorage(CollectionTestCase): """ hashed_file_path = hashed_file_path + def setUp(self): + storage.staticfiles_storage.hashed_files.clear() # avoid cache interference + super(TestCollectionSimpleCachedStorage, self).setUp() + def test_template_tag_return(self): """ Test the CachedStaticFilesStorage backend. |
