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_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()
示例#3
0
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()
示例#4
0
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
示例#5
0
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
示例#7
0
def do_thumbnailing(content, name, *args, **kwargs):
    source = Thumbnailer(file=BytesIO(content), name=name)
    source.url = '/media/' + name
    return thumbnail(source, *args, **kwargs)
示例#8
0
def test_thumbnailing_svg_without_url():
    source = Thumbnailer(file=BytesIO(TEST_SVG), name='test.svg')
    assert not hasattr(source, 'url')
    assert thumbnail(source) is None
示例#9
0
def test_thumbnailing_with_none_as_thumbnailer():
    source = Thumbnailer(file=BytesIO(TEST_PNG), name='test.png')
    source.easy_thumbnails_thumbnailer = None
    assert thumbnail(source) is None
示例#10
0
def test_thumbnailing_none():
    assert thumbnail(None) is None
def test_thumbnailing_svg_without_url():
    source = Thumbnailer(file=BytesIO(TEST_SVG), name='test.svg')
    assert not hasattr(source, 'url')
    assert thumbnail(source) is None
def test_thumbnailing_with_none_as_thumbnailer():
    source = Thumbnailer(file=BytesIO(TEST_PNG), name='test.png')
    source.easy_thumbnails_thumbnailer = None
    assert thumbnail(source) is None
def test_thumbnailing_none():
    assert thumbnail(None) is None
def do_thumbnailing(content, name, *args, **kwargs):
    source = Thumbnailer(file=BytesIO(content), name=name)
    source.url = '/media/' + name
    return thumbnail(source, *args, **kwargs)