def test_thumbnailing_nonseekable_svg_file(): class DummyFile(BytesIO): def tell(self): raise IOError('DummyFile does not support tell/seek') seek = tell source = Thumbnailer(file=DummyFile(TEST_SVG), name='test.svg') source.url = '/media/test.svg' assert thumbnail(source) is None
def test_thumbnailing_nonseekable_svg_file(): class DummyFile(BytesIO): def tell(self): raise IOError('DummyFile does not support tell/seek') seek = tell source = Thumbnailer(file=DummyFile(TEST_SVG), name='test.svg') source.url = '/media/test.svg' assert thumbnail(source) is None
def test_thumbnailing_nonseekable_svg_file(): class DummyFile(BytesIO): def tell(self): raise IOError('DummyFile does not support tell/seek') seek = tell source = Thumbnailer(file=DummyFile(TEST_SVG), name='test.svg') source.url = '/media/test.svg' # Well if the merchant tries his luck with non seekable file # and decides to name it as svg then he might not have working # front. Also not worth thumbnail these anyways so might as well # return the source url. assert thumbnail(source) == source.url
def test_thumbnailing_nonseekable_svg_file(): class DummyFile(BytesIO): def tell(self): raise IOError('DummyFile does not support tell/seek') seek = tell source = Thumbnailer(file=DummyFile(TEST_SVG), name='test.svg') source.url = '/media/test.svg' # Well if the merchant tries his luck with non seekable file # and decides to name it as svg then he might not have working # front. Also not worth thumbnail these anyways so might as well # return the source url. assert thumbnail(source) == source.url
def test_thumbnail_cache(): image1 = factories.get_random_filer_image() image2 = factories.get_random_filer_image() media = ProductMedia.objects.create(product=factories.get_default_product(), file=image2) cache_key, cached_url = _get_cached_thumbnail_url(image1, alias=None, generate=True) assert cache_key and not cached_url url = thumbnail(image1) cache_key, cached_url = _get_cached_thumbnail_url(image1, alias=None, generate=True) assert cache_key and cached_url == url cache_key, cached_url = _get_cached_thumbnail_url(media, alias=None, generate=True) assert cache_key and not cached_url url = thumbnail(media) cache_key, cached_url = _get_cached_thumbnail_url(media, alias=None, generate=True) assert cache_key and cached_url == url img_url = "http://www.shuup.com/logo.png" cache_key, cached_url = _get_cached_thumbnail_url(img_url, alias=None, generate=True) assert cache_key and not cached_url url = thumbnail(img_url) cache_key, cached_url = _get_cached_thumbnail_url(img_url, alias=None, generate=True) assert cache_key and cached_url == url source = Thumbnailer(file=BytesIO(TEST_PNG), name="logo.png") source.url = '/media/logo.png' cache_key, cached_url = _get_cached_thumbnail_url(source, alias=None, generate=True) assert cache_key and not cached_url url = thumbnail(source) cache_key, cached_url = _get_cached_thumbnail_url(source, alias=None, generate=True) assert cache_key and cached_url == url # check whether caches are bumped image1.save() cache_key, cached_url = _get_cached_thumbnail_url(image1, alias=None, generate=True) assert cache_key and not cached_url media.save() cache_key, cached_url = _get_cached_thumbnail_url(media, alias=None, generate=True) assert cache_key and not cached_url media.delete() image1.delete() image2.delete()
def test_thumbnail_cache(): image1 = factories.get_random_filer_image() image2 = factories.get_random_filer_image() media = ProductMedia.objects.create(product=factories.get_default_product(), file=image2) cache_key, cached_url = _get_cached_thumbnail_url(image1, alias=None, generate=True) assert cache_key and not cached_url url = thumbnail(image1) cache_key, cached_url = _get_cached_thumbnail_url(image1, alias=None, generate=True) assert cache_key and cached_url == url cache_key, cached_url = _get_cached_thumbnail_url(media, alias=None, generate=True) assert cache_key and not cached_url url = thumbnail(media) cache_key, cached_url = _get_cached_thumbnail_url(media, alias=None, generate=True) assert cache_key and cached_url == url img_url = "http://www.E-Commerce.com/logo.png" cache_key, cached_url = _get_cached_thumbnail_url(img_url, alias=None, generate=True) assert cache_key and not cached_url url = thumbnail(img_url) cache_key, cached_url = _get_cached_thumbnail_url(img_url, alias=None, generate=True) assert cache_key and cached_url == url source = Thumbnailer(file=BytesIO(TEST_PNG), name="logo.png") source.url = '/media/logo.png' cache_key, cached_url = _get_cached_thumbnail_url(source, alias=None, generate=True) assert cache_key and not cached_url url = thumbnail(source) cache_key, cached_url = _get_cached_thumbnail_url(source, alias=None, generate=True) assert cache_key and cached_url == url # check whether caches are bumped image1.save() cache_key, cached_url = _get_cached_thumbnail_url(image1, alias=None, generate=True) assert cache_key and not cached_url media.save() cache_key, cached_url = _get_cached_thumbnail_url(media, alias=None, generate=True) assert cache_key and not cached_url media.delete() image1.delete() image2.delete()
def do_thumbnailing(content, name, *args, **kwargs): source = Thumbnailer(file=BytesIO(content), name=name) source.url = '/media/' + name return thumbnail(source, *args, **kwargs)
def do_thumbnailing(content, name, *args, **kwargs): source = Thumbnailer(file=BytesIO(content), name=name) source.url = '/media/' + name return thumbnail(source, *args, **kwargs)