Moved get_hashed_mtime to compressor.utils from tests.

This commit is contained in:
Jannis Leidel
2010-09-16 11:50:03 +02:00
parent 062796336f
commit ccea0116d7
2 changed files with 9 additions and 6 deletions

View File

@@ -24,6 +24,11 @@ def get_mtime(filename):
return mtime return mtime
return os.path.getmtime(filename) return os.path.getmtime(filename)
def get_hashed_mtime(filename, length=12):
filename = os.path.realpath(filename)
mtime = str(int(get_mtime(filename)))
return get_hexdigest(mtime)[:length]
def get_class(class_string, exception=FilterError): def get_class(class_string, exception=FilterError):
""" """

View File

@@ -12,7 +12,7 @@ from django.core.cache.backends import dummy
from compressor import CssCompressor, JsCompressor, storage from compressor import CssCompressor, JsCompressor, storage
from compressor.conf import settings from compressor.conf import settings
from compressor.storage import CompressorFileStorage from compressor.storage import CompressorFileStorage
from compressor.utils import get_hexdigest, get_mtime from compressor.utils import get_hashed_mtime
class CompressorTestCase(TestCase): class CompressorTestCase(TestCase):
@@ -111,6 +111,7 @@ class CompressorTestCase(TestCase):
self.assertEqual(output, JsCompressor(self.js).output()) self.assertEqual(output, JsCompressor(self.js).output())
settings.OUTPUT_DIR = old_output_dir settings.OUTPUT_DIR = old_output_dir
class LxmlCompressorTestCase(CompressorTestCase): class LxmlCompressorTestCase(CompressorTestCase):
def test_css_split(self): def test_css_split(self):
@@ -131,10 +132,6 @@ class LxmlCompressorTestCase(CompressorTestCase):
def tearDown(self): def tearDown(self):
settings.PARSER = self.old_parser settings.PARSER = self.old_parser
def get_hashed_mtime(filename, length=12):
filename = os.path.realpath(filename)
mtime = str(int(get_mtime(filename)))
return get_hexdigest(mtime)[:length]
class CssAbsolutizingTestCase(TestCase): class CssAbsolutizingTestCase(TestCase):
def setUp(self): def setUp(self):
@@ -181,7 +178,6 @@ class CssAbsolutizingTestCase(TestCase):
output = "p { background: url('%simages/image.gif?%s') }" % (settings.MEDIA_URL, get_hashed_mtime(filename)) output = "p { background: url('%simages/image.gif?%s') }" % (settings.MEDIA_URL, get_hashed_mtime(filename))
self.assertEqual(output, filter.input(filename=filename)) self.assertEqual(output, filter.input(filename=filename))
def test_css_hunks(self): def test_css_hunks(self):
hash_dict = { hash_dict = {
'hash1': get_hashed_mtime(os.path.join(settings.MEDIA_ROOT, 'css/url/url1.css')), 'hash1': get_hashed_mtime(os.path.join(settings.MEDIA_ROOT, 'css/url/url1.css')),
@@ -326,6 +322,7 @@ class TemplatetagTestCase(TestCase):
{% endcompress %}""" {% endcompress %}"""
self.assertRaises(TemplateSyntaxError, render, template, {}) self.assertRaises(TemplateSyntaxError, render, template, {})
class TestStorage(CompressorFileStorage): class TestStorage(CompressorFileStorage):
""" """
Test compressor storage that gzips storage files Test compressor storage that gzips storage files
@@ -339,6 +336,7 @@ class TestStorage(CompressorFileStorage):
out.writelines(open(self.path(filename), 'rb')) out.writelines(open(self.path(filename), 'rb'))
out.close() out.close()
class StorageTestCase(TestCase): class StorageTestCase(TestCase):
def setUp(self): def setUp(self):
self._storage = storage.default_storage self._storage = storage.default_storage