def testImageCacheForSameSizeImageLeavesImageUnmodified(self): asset, image_size = get_test_thumbnail_asset() width, height = image_size thumbnail = default_thumbnail_cache.get_thumbnail(asset, width, height, "resize") self.assertEqual(thumbnail.width, width) self.assertEqual(thumbnail.height, height) # Make sure the assets are identical. self.assertEqual(hashlib.sha1(default_storage.open(default_asset_cache.get_name(asset)).read()).hexdigest(), hashlib.sha1(default_storage.open(default_asset_cache.get_name(thumbnail._asset)).read()).hexdigest())
def testImageCacheThumbnailLarger(self): asset, image_size = get_test_thumbnail_asset() width, height = image_size width *= 3 height *= 2 thumbnail = default_thumbnail_cache.get_thumbnail(asset, width, height, "proportional") self.assertNotEqual(thumbnail.width, width) self.assertEqual(thumbnail.height, height) # Make sure the file contents are not identical. self.assertEqual(hashlib.sha1(default_storage.open(default_asset_cache.get_name(asset)).read()).hexdigest(), hashlib.sha1(default_storage.open(default_asset_cache.get_name(thumbnail._asset)).read()).hexdigest())
def testGetImgTag(self): asset, image_size = get_test_thumbnail_asset() width, height = image_size width /= 2 height /= 2 thumbnail = default_thumbnail_cache.get_thumbnail(asset, width, height, "resize") self.assertEqual( Template("{% load assets %}{% get_img asset width=width height=height method='resize' as img %}{{img.url}}:{{img.width}}:{{img.height}}").render(Context({ "asset": asset, "width": width, "height": height, })), u'{src}:{width}:{height}'.format( src = thumbnail.url, width = thumbnail.width, height = thumbnail.height, ), )
def testImgTag(self): asset, image_size = get_test_thumbnail_asset() width, height = image_size width /= 2 height /= 2 thumbnail = default_thumbnail_cache.get_thumbnail(asset, width, height, "resize") self.assertEqual( Template("{% load assets %}{% img asset width=width height=height method='resize' %}").render(Context({ "asset": asset, "width": width, "height": height, })), u'<img src="{src}" width={width} height={height} alt="">'.format( src = thumbnail.url, width = thumbnail.width, height = thumbnail.height, ), )