Permalink
Browse files

Add tests for previous commit (issue #126)

  • Loading branch information...
1 parent 483c201 commit 0136c3b92f4289c01d8b1ad847010fbd80b953f3 @jonasvp jonasvp committed Feb 8, 2012
Showing with 33 additions and 10 deletions.
  1. +31 −10 compressor/tests/filters.py
  2. +1 −0 compressor/tests/media/css/url/2/url2.css
  3. +1 −0 compressor/tests/media/css/url/url1.css
View
41 compressor/tests/filters.py
@@ -85,7 +85,8 @@ def test_cssmin_filter(self):
class CssAbsolutizingTestCase(TestCase):
hashing_method = 'mtime'
hashing_func = staticmethod(get_hashed_mtime)
- content = "p { background: url('../../img/python.png') }"
+ content = ("p { background: url('../../img/python.png') }"
+ "p { filter: Alpha(src='../../img/python.png') }")
def setUp(self):
self.old_enabled = settings.COMPRESS_ENABLED
@@ -108,36 +109,54 @@ def tearDown(self):
def test_css_absolute_filter(self):
filename = os.path.join(settings.COMPRESS_ROOT, 'css/url/test.css')
imagefilename = os.path.join(settings.COMPRESS_ROOT, 'img/python.png')
- output = "p { background: url('%simg/python.png?%s') }" % (settings.COMPRESS_URL, self.hashing_func(imagefilename))
+ params = {
+ 'url': settings.COMPRESS_URL,
+ 'hash': self.hashing_func(imagefilename),
+ }
+ output = ("p { background: url('%(url)simg/python.png?%(hash)s') }"
+ "p { filter: Alpha(src='%(url)simg/python.png?%(hash)s') }") % params
filter = CssAbsoluteFilter(self.content)
self.assertEqual(output, filter.input(filename=filename, basename='css/url/test.css'))
- settings.COMPRESS_URL = 'http://media.example.com/'
+ settings.COMPRESS_URL = params['url'] = 'http://media.example.com/'
filter = CssAbsoluteFilter(self.content)
filename = os.path.join(settings.COMPRESS_ROOT, 'css/url/test.css')
- output = "p { background: url('%simg/python.png?%s') }" % (settings.COMPRESS_URL, self.hashing_func(imagefilename))
+ output = ("p { background: url('%(url)simg/python.png?%(hash)s') }"
+ "p { filter: Alpha(src='%(url)simg/python.png?%(hash)s') }") % params
self.assertEqual(output, filter.input(filename=filename, basename='css/url/test.css'))
def test_css_absolute_filter_https(self):
filename = os.path.join(settings.COMPRESS_ROOT, 'css/url/test.css')
imagefilename = os.path.join(settings.COMPRESS_ROOT, 'img/python.png')
- output = "p { background: url('%simg/python.png?%s') }" % (settings.COMPRESS_URL, self.hashing_func(imagefilename))
+ params = {
+ 'url': settings.COMPRESS_URL,
+ 'hash': self.hashing_func(imagefilename),
+ }
+ output = ("p { background: url('%(url)simg/python.png?%(hash)s') }"
+ "p { filter: Alpha(src='%(url)simg/python.png?%(hash)s') }") % params
filter = CssAbsoluteFilter(self.content)
self.assertEqual(output, filter.input(filename=filename, basename='css/url/test.css'))
- settings.COMPRESS_URL = 'https://media.example.com/'
+ settings.COMPRESS_URL = params['url'] = 'https://media.example.com/'
filter = CssAbsoluteFilter(self.content)
filename = os.path.join(settings.COMPRESS_ROOT, 'css/url/test.css')
- output = "p { background: url('%simg/python.png?%s') }" % (settings.COMPRESS_URL, self.hashing_func(imagefilename))
+ output = ("p { background: url('%(url)simg/python.png?%(hash)s') }"
+ "p { filter: Alpha(src='%(url)simg/python.png?%(hash)s') }") % params
self.assertEqual(output, filter.input(filename=filename, basename='css/url/test.css'))
def test_css_absolute_filter_relative_path(self):
filename = os.path.join(settings.TEST_DIR, 'whatever', '..', 'media', 'whatever/../css/url/test.css')
imagefilename = os.path.join(settings.COMPRESS_ROOT, 'img/python.png')
- output = "p { background: url('%simg/python.png?%s') }" % (settings.COMPRESS_URL, self.hashing_func(imagefilename))
+ params = {
+ 'url': settings.COMPRESS_URL,
+ 'hash': self.hashing_func(imagefilename),
+ }
+ output = ("p { background: url('%(url)simg/python.png?%(hash)s') }"
+ "p { filter: Alpha(src='%(url)simg/python.png?%(hash)s') }") % params
filter = CssAbsoluteFilter(self.content)
self.assertEqual(output, filter.input(filename=filename, basename='css/url/test.css'))
- settings.COMPRESS_URL = 'https://media.example.com/'
+ settings.COMPRESS_URL = params['url'] = 'https://media.example.com/'
filter = CssAbsoluteFilter(self.content)
- output = "p { background: url('%simg/python.png?%s') }" % (settings.COMPRESS_URL, self.hashing_func(imagefilename))
+ output = ("p { background: url('%(url)simg/python.png?%(hash)s') }"
+ "p { filter: Alpha(src='%(url)simg/python.png?%(hash)s') }") % params
self.assertEqual(output, filter.input(filename=filename, basename='css/url/test.css'))
def test_css_hunks(self):
@@ -150,12 +169,14 @@ def test_css_hunks(self):
p { background: url('/media/img/python.png?%(hash1)s'); }
p { background: url('/media/img/python.png?%(hash1)s'); }
p { background: url('/media/img/python.png?%(hash1)s'); }
+p { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/media/img/python.png?%(hash1)s'); }
""" % hash_dict,
u"""\
p { background: url('/media/img/add.png?%(hash2)s'); }
p { background: url('/media/img/add.png?%(hash2)s'); }
p { background: url('/media/img/add.png?%(hash2)s'); }
p { background: url('/media/img/add.png?%(hash2)s'); }
+p { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/media/img/add.png?%(hash2)s'); }
""" % hash_dict], list(self.css_node.hunks()))
def test_guess_filename(self):
View
1 compressor/tests/media/css/url/2/url2.css
@@ -2,3 +2,4 @@ p { background: url('../../../img/add.png'); }
p { background: url(../../../img/add.png); }
p { background: url( ../../../img/add.png ); }
p { background: url( '../../../img/add.png' ); }
+p { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../../../img/add.png'); }
View
1 compressor/tests/media/css/url/url1.css
@@ -2,3 +2,4 @@ p { background: url('../../img/python.png'); }
p { background: url(../../img/python.png); }
p { background: url( ../../img/python.png ); }
p { background: url( '../../img/python.png' ); }
+p { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../../img/python.png'); }

0 comments on commit 0136c3b

Please sign in to comment.