|
@@ -43,6 +43,15 @@ class TestGzipCache(unittest.TestCase):
|
|
|
self.assertFalse(gzip_cache.should_compress('baz.mp3'))
|
|
|
self.assertFalse(gzip_cache.should_compress('foo.mov'))
|
|
|
|
|
|
+ def test_should_overwrite(self):
|
|
|
+ # Default to false if GZIP_CACHE_OVERWRITE is not set
|
|
|
+ settings = { }
|
|
|
+ self.assertFalse(gzip_cache.should_overwrite(settings))
|
|
|
+ settings = { 'GZIP_CACHE_OVERWRITE': False }
|
|
|
+ self.assertFalse(gzip_cache.should_overwrite(settings))
|
|
|
+ settings = { 'GZIP_CACHE_OVERWRITE': True }
|
|
|
+ self.assertTrue(gzip_cache.should_overwrite(settings))
|
|
|
+
|
|
|
def test_creates_gzip_file(self):
|
|
|
# A file matching the input filename with a .gz extension is created.
|
|
|
|
|
@@ -51,7 +60,7 @@ class TestGzipCache(unittest.TestCase):
|
|
|
# not report it). Therefore, create a dummy file to use.
|
|
|
with temporary_folder() as tempdir:
|
|
|
_, a_html_filename = tempfile.mkstemp(suffix='.html', dir=tempdir)
|
|
|
- gzip_cache.create_gzip_file(a_html_filename)
|
|
|
+ gzip_cache.create_gzip_file(a_html_filename, False)
|
|
|
self.assertTrue(os.path.exists(a_html_filename + '.gz'))
|
|
|
|
|
|
def test_creates_same_gzip_file(self):
|
|
@@ -63,13 +72,24 @@ class TestGzipCache(unittest.TestCase):
|
|
|
with temporary_folder() as tempdir:
|
|
|
_, a_html_filename = tempfile.mkstemp(suffix='.html', dir=tempdir)
|
|
|
a_gz_filename = a_html_filename + '.gz'
|
|
|
- gzip_cache.create_gzip_file(a_html_filename)
|
|
|
+ gzip_cache.create_gzip_file(a_html_filename, False)
|
|
|
gzip_hash = get_md5(a_gz_filename)
|
|
|
time.sleep(1)
|
|
|
- gzip_cache.create_gzip_file(a_html_filename)
|
|
|
+ gzip_cache.create_gzip_file(a_html_filename, False)
|
|
|
self.assertEqual(gzip_hash, get_md5(a_gz_filename))
|
|
|
|
|
|
+ def test_overwrites_gzip_file(self):
|
|
|
+ # A file matching the input filename with a .gz extension is not created.
|
|
|
+
|
|
|
+ # The plugin walks over the output content after the finalized signal
|
|
|
+ # so it is safe to assume that the file exists (otherwise walk would
|
|
|
+ # not report it). Therefore, create a dummy file to use.
|
|
|
+ with temporary_folder() as tempdir:
|
|
|
+ _, a_html_filename = tempfile.mkstemp(suffix='.html', dir=tempdir)
|
|
|
+ gzip_cache.create_gzip_file(a_html_filename, True)
|
|
|
+ self.assertFalse(os.path.exists(a_html_filename + '.gz'))
|
|
|
|
|
|
def get_md5(filepath):
|
|
|
with open(filepath, 'rb') as fh:
|
|
|
return md5(fh.read()).hexdigest()
|
|
|
+
|