summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJannis Leidel <jannis@leidel.info>2012-05-16 13:21:46 +0200
committerJannis Leidel <jannis@leidel.info>2012-05-16 13:21:50 +0200
commit5f75ac91df2ef1c19946f65e08aa50165f061cd4 (patch)
treeb26e5faf50074bc8b84696adf4e33d2bea31658c /tests
parent085c03e08b29fafc92ef49c2a3717ec23cf1c500 (diff)
Fixed #17896 -- Added file_hash method to CachedStaticFilesStorage to be able to customize the way the hashed name of a file is created. Thanks to mkai for the initial patch.
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/staticfiles_tests/storage.py7
-rw-r--r--tests/regressiontests/staticfiles_tests/tests.py40
2 files changed, 46 insertions, 1 deletions
diff --git a/tests/regressiontests/staticfiles_tests/storage.py b/tests/regressiontests/staticfiles_tests/storage.py
index 8358f833c8..4d49e6fbb2 100644
--- a/tests/regressiontests/staticfiles_tests/storage.py
+++ b/tests/regressiontests/staticfiles_tests/storage.py
@@ -1,5 +1,6 @@
from datetime import datetime
from django.core.files import storage
+from django.contrib.staticfiles.storage import CachedStaticFilesStorage
class DummyStorage(storage.Storage):
"""
@@ -17,3 +18,9 @@ class DummyStorage(storage.Storage):
def modified_time(self, name):
return datetime.date(1970, 1, 1)
+
+
+class SimpleCachedStaticFilesStorage(CachedStaticFilesStorage):
+
+ def file_hash(self, name, content=None):
+ return 'deploy12345'
diff --git a/tests/regressiontests/staticfiles_tests/tests.py b/tests/regressiontests/staticfiles_tests/tests.py
index 7f30cb987a..0c247e4a17 100644
--- a/tests/regressiontests/staticfiles_tests/tests.py
+++ b/tests/regressiontests/staticfiles_tests/tests.py
@@ -10,7 +10,7 @@ from StringIO import StringIO
from django.template import loader, Context
from django.conf import settings
-from django.core.cache.backends.base import BaseCache, CacheKeyWarning
+from django.core.cache.backends.base import BaseCache
from django.core.exceptions import ImproperlyConfigured
from django.core.files.storage import default_storage
from django.core.management import call_command
@@ -515,6 +515,44 @@ class TestCollectionCachedStorage(BaseCollectionTestCase,
self.assertEqual(cache_key, 'staticfiles:e95bbc36387084582df2a70750d7b351')
+# we set DEBUG to False here since the template tag wouldn't work otherwise
+@override_settings(**dict(TEST_SETTINGS,
+ STATICFILES_STORAGE='regressiontests.staticfiles_tests.storage.SimpleCachedStaticFilesStorage',
+ DEBUG=False,
+))
+class TestCollectionSimpleCachedStorage(BaseCollectionTestCase,
+ BaseStaticFilesTestCase, TestCase):
+ """
+ Tests for the Cache busting storage
+ """
+ def cached_file_path(self, path):
+ fullpath = self.render_template(self.static_template_snippet(path))
+ return fullpath.replace(settings.STATIC_URL, '')
+
+ def test_template_tag_return(self):
+ """
+ Test the CachedStaticFilesStorage backend.
+ """
+ self.assertStaticRaises(ValueError,
+ "does/not/exist.png",
+ "/static/does/not/exist.png")
+ self.assertStaticRenders("test/file.txt",
+ "/static/test/file.deploy12345.txt")
+ self.assertStaticRenders("cached/styles.css",
+ "/static/cached/styles.deploy12345.css")
+ self.assertStaticRenders("path/",
+ "/static/path/")
+ self.assertStaticRenders("path/?query",
+ "/static/path/?query")
+
+ def test_template_tag_simple_content(self):
+ relpath = self.cached_file_path("cached/styles.css")
+ self.assertEqual(relpath, "cached/styles.deploy12345.css")
+ with storage.staticfiles_storage.open(relpath) as relfile:
+ content = relfile.read()
+ self.assertNotIn("cached/other.css", content)
+ self.assertIn("other.deploy12345.css", content)
+
if sys.platform != 'win32':
class TestCollectionLinks(CollectionTestCase, TestDefaults):