Fix issue #69 , modifying tests to demonstrate the initial problem. Code for get_offline_cachekey by pilt (Simon Pantzare).
This commit is contained in:

committed by
Jannis Leidel

parent
181b66c708
commit
00ea7e2fc7
@@ -25,8 +25,8 @@ def get_mtime_cachekey(filename):
|
||||
|
||||
|
||||
def get_offline_cachekey(source):
|
||||
return get_cachekey(
|
||||
"offline.%s" % get_hexdigest("".join(smart_str(s) for s in source)))
|
||||
to_hexdigest = [smart_str(getattr(s, 's', s)) for s in source]
|
||||
return get_cachekey("offline.%s" % get_hexdigest(to_hexdigest))
|
||||
|
||||
|
||||
def get_templatetag_cachekey(compressor, mode, kind):
|
||||
|
2
compressor/tests/runtests.py
Normal file → Executable file
2
compressor/tests/runtests.py
Normal file → Executable file
@@ -10,7 +10,7 @@ TEST_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
if not settings.configured:
|
||||
settings.configure(
|
||||
COMPRESS_CACHE_BACKEND = 'dummy://',
|
||||
COMPRESS_CACHE_BACKEND = 'locmem://',
|
||||
DATABASE_ENGINE='sqlite3',
|
||||
INSTALLED_APPS=[
|
||||
'compressor',
|
||||
|
@@ -1,4 +1,5 @@
|
||||
{% load compress %}
|
||||
{% spaceless %}
|
||||
{% compress css%}
|
||||
<style type="text/css">
|
||||
body {
|
||||
@@ -12,3 +13,10 @@
|
||||
alert("test");
|
||||
</script>
|
||||
{% endcompress %}
|
||||
|
||||
{% compress js%}
|
||||
<script type="text/javascript">
|
||||
alert("test 2");
|
||||
</script>
|
||||
{% endcompress %}
|
||||
{% endspaceless %}
|
||||
|
@@ -21,7 +21,7 @@ try:
|
||||
except ImportError:
|
||||
BeautifulSoup = None
|
||||
|
||||
from django.core.cache.backends import dummy
|
||||
from django.core.cache.backends import locmem
|
||||
from django.core.files.storage import get_storage_class
|
||||
from django.template import Template, Context, TemplateSyntaxError
|
||||
from django.test import TestCase
|
||||
@@ -442,7 +442,7 @@ class CacheBackendTestCase(CompressorTestCase):
|
||||
|
||||
def test_correct_backend(self):
|
||||
from compressor.cache import cache
|
||||
self.assertEqual(cache.__class__, dummy.CacheClass)
|
||||
self.assertEqual(cache.__class__, locmem.CacheClass)
|
||||
|
||||
|
||||
class OfflineGenerationTestCase(TestCase):
|
||||
@@ -451,18 +451,28 @@ class OfflineGenerationTestCase(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self._old_compress = settings.COMPRESS_ENABLED
|
||||
self._old_compress_offline = settings.COMPRESS_OFFLINE
|
||||
settings.COMPRESS_ENABLED = True
|
||||
settings.COMPRESS_OFFLINE = True
|
||||
self.template_file = open("templates/test_compressor_offline.html")
|
||||
self.template = Template(self.template_file.read().decode(settings.FILE_CHARSET))
|
||||
|
||||
def tearDown(self):
|
||||
settings.COMPRESS_ENABLED = self._old_compress
|
||||
settings.COMPRESS_OFFLINE = self._old_compress_offline
|
||||
|
||||
def test_offline(self):
|
||||
count, result = CompressCommand().compress()
|
||||
self.assertEqual(2, count)
|
||||
self.assertEqual(3, count)
|
||||
self.assertEqual([
|
||||
css_tag('/media/CACHE/css/cd579b7deb7d.css')+'\n',
|
||||
u'<script type="text/javascript" src="/media/CACHE/js/0a2bb9a287c0.js" charset="utf-8"></script>',
|
||||
u'<script type="text/javascript" src="/media/CACHE/js/fb1736ad48b7.js" charset="utf-8"></script>',
|
||||
], result)
|
||||
# Template rendering should use the cache. FIXME: how to make sure of it ? Should we test the cache
|
||||
# key<->values ourselves?
|
||||
rendered_template = self.template.render(Context({})).replace("\n", "")
|
||||
self.assertEqual(rendered_template, "".join(result).replace("\n", ""))
|
||||
|
||||
def test_offline_with_context(self):
|
||||
self._old_offline_context = settings.COMPRESS_OFFLINE_CONTEXT
|
||||
@@ -470,11 +480,16 @@ class OfflineGenerationTestCase(TestCase):
|
||||
'color': 'blue',
|
||||
}
|
||||
count, result = CompressCommand().compress()
|
||||
self.assertEqual(2, count)
|
||||
self.assertEqual(3, count)
|
||||
self.assertEqual([
|
||||
css_tag('/media/CACHE/css/ee62fbfd116a.css')+'\n',
|
||||
u'<script type="text/javascript" src="/media/CACHE/js/0a2bb9a287c0.js" charset="utf-8"></script>',
|
||||
u'<script type="text/javascript" src="/media/CACHE/js/fb1736ad48b7.js" charset="utf-8"></script>',
|
||||
], result)
|
||||
# Template rendering should use the cache. FIXME: how to make sure of it ? Should we test the cache
|
||||
# key<->values ourselves?
|
||||
rendered_template = self.template.render(Context(settings.COMPRESS_OFFLINE_CONTEXT)).replace("\n", "")
|
||||
self.assertEqual(rendered_template, "".join(result).replace("\n", ""))
|
||||
settings.COMPRESS_OFFLINE_CONTEXT = self._old_offline_context
|
||||
|
||||
def test_get_loaders(self):
|
||||
|
Reference in New Issue
Block a user