예제 #1
0
 def test_filename_in_debug_mode(self):
     # In debug mode, compressor should look for files using staticfiles
     # finders only, and not look into the global static directory, where
     # files can be outdated
     css_filename = os.path.join(settings.COMPRESS_ROOT, "css", "one.css")
     # Store the hash of the original file's content
     with open(css_filename) as f:
         css_content = f.read()
     hashed = get_hexdigest(css_content, 12)
     # Now modify the file in the STATIC_ROOT
     test_css_content = "p { font-family: 'test' }"
     with open(css_filename, "a") as css:
         css.write("\n")
         css.write(test_css_content)
     # We should generate a link with the hash of the original content, not
     # the modified one
     expected = '<link rel="stylesheet" href="/static/CACHE/css/%s.css" type="text/css" />' % hashed
     compressor = CssCompressor(self.css)
     compressor.storage = DefaultStorage()
     output = compressor.output()
     self.assertEqual(expected, output)
     with open(os.path.join(settings.COMPRESS_ROOT, "CACHE", "css",
                            "%s.css" % hashed), "r") as f:
         result = f.read()
     self.assertTrue(test_css_content not in result)
예제 #2
0
 def compare():
     expected = '<link rel="stylesheet" href="/static/CACHE/css/%s.css" type="text/css">' % self.expected_css_hash
     compressor = CssCompressor('css', self.css)
     compressor.storage = DefaultStorage()
     output = compressor.output()
     self.assertEqual(expected, output)