Commit fabeffa8 by Timothée Peignier

test versioning class and fix some logic too

parent 8f58c719
...@@ -10,12 +10,12 @@ class Versioning(object): ...@@ -10,12 +10,12 @@ class Versioning(object):
def __init__(self, verbose=False): def __init__(self, verbose=False):
self.verbose = verbose self.verbose = verbose
def versionner(self): def versioner(self):
return to_class(settings.PIPELINE_VERSIONING)(self) return to_class(settings.PIPELINE_VERSIONING)(self)
versionner = property(versionner) versioner = property(versioner)
def version(self, paths): def version(self, paths):
return getattr(self.versionner, 'version')(paths) return getattr(self.versioner, 'version')(paths)
def version_from_file(self, path, filename): def version_from_file(self, path, filename):
filename = settings.PIPELINE_VERSION_PLACEHOLDER.join([re.escape(part) for part in filename.split(settings.PIPELINE_VERSION_PLACEHOLDER)]) filename = settings.PIPELINE_VERSION_PLACEHOLDER.join([re.escape(part) for part in filename.split(settings.PIPELINE_VERSION_PLACEHOLDER)])
...@@ -41,10 +41,10 @@ class Versioning(object): ...@@ -41,10 +41,10 @@ class Versioning(object):
output_file = self.output_filename(output_file, version) output_file = self.output_filename(output_file, version)
if not storage.exists(output_file): if not storage.exists(output_file):
return True, version return True, version
return getattr(self.versionner, 'need_update')(output_file, paths, version) return getattr(self.versioner, 'need_update')(output_file, paths, version)
def cleanup(self, filename): def cleanup(self, filename):
if not settings.PIPELINE_VERSION and not settings.PIPELINE_VERSION_REMOVE_OLD: if not (settings.PIPELINE_VERSION and settings.PIPELINE_VERSION_REMOVE_OLD):
return # Nothing to delete here return # Nothing to delete here
path = os.path.dirname(filename) path = os.path.dirname(filename)
filename = settings.PIPELINE_VERSION_PLACEHOLDER.join([re.escape(part) for part in filename.split(settings.PIPELINE_VERSION_PLACEHOLDER)]) filename = settings.PIPELINE_VERSION_PLACEHOLDER.join([re.escape(part) for part in filename.split(settings.PIPELINE_VERSION_PLACEHOLDER)])
......
from mock import patch
from django.test import TestCase from django.test import TestCase
from pipeline.conf import settings
from pipeline.storage import storage
from pipeline.versioning import Versioning
from pipeline.versioning.mtime import MTimeVersioning
class VersioningTest(TestCase): class VersioningTest(TestCase):
pass def setUp(self):
self.versioning = Versioning()
self.old_pipeline_version = settings.PIPELINE_VERSION
def test_versioner_class(self):
self.assertTrue(isinstance(self.versioning.versioner, MTimeVersioning))
def test_output_filename(self):
output_filename = self.versioning.output_filename("css/master.?.css",
"1308127956")
self.assertEquals(output_filename, 'css/master.0.css')
def test_output_filename_with_version(self):
settings.PIPELINE_VERSION = True
output_filename = self.versioning.output_filename("css/master.?.css",
"1308127956")
self.assertEquals(output_filename, 'css/master.1308127956.css')
@patch.object(MTimeVersioning, 'version')
def test_need_update(self, mock):
mock.return_value = "1307480052"
need_update, version = self.versioning.need_update('css/master.1308127956.css',
['css/first.css'],
)
self.assertEquals(need_update, True)
self.assertEquals(version, "1307480052")
@patch.object(MTimeVersioning, 'need_update')
def test_no_update(self, mock):
mock.return_value = (False, "123456")
need_update, version = self.versioning.need_update('css/master.123456.css',
['css/first.css'],
)
self.assertTrue(mock.called)
self.assertEquals(need_update, False)
self.assertEquals(version, "123456")
@patch.object(MTimeVersioning, 'version')
def test_version(self, mock):
mock.return_value = "123456"
version = self.versioning.version(['css/first.css'])
self.assertTrue(mock.called)
self.assertEquals(version, "123456")
def test_version_from_file(self):
settings.PIPELINE_VERSION = True
version = self.versioning.version_from_file('css/',
"master.?.css")
self.assertEquals(version, "123456")
@patch.object(storage, 'exists')
def test_no_cleanup(self, mock):
self.versioning.cleanup('css/master.?.css')
self.assertFalse(mock.called)
@patch.object(storage, 'delete')
def test_cleanup(self, mock):
settings.PIPELINE_VERSION = True
self.versioning.cleanup('css/master.?.css')
mock.assert_called_with('css/master.123456.css')
def tearDown(self):
settings.PIPELINE_VERSION = self.old_pipeline_version
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment