Beispiel #1
0
def test_memcached_cache_key():
    """
    Ensure the default cachefile backend is sanitizing its cache key for
    memcached by default.

    """
    class MockFile(object):
        def __init__(self, name):
            self.name = name

    backend = Simple()
    extra_char_count = len('state-') + len(settings.IMAGEKIT_CACHE_PREFIX)

    length = 199 - extra_char_count
    filename = '1' * length
    file = MockFile(filename)
    eq_(backend.get_key(file),
        '%s%s-state' % (settings.IMAGEKIT_CACHE_PREFIX, file.name))

    length = 200 - extra_char_count
    filename = '1' * length
    file = MockFile(filename)
    eq_(
        backend.get_key(file), '%s%s:%s' %
        (settings.IMAGEKIT_CACHE_PREFIX, '1' *
         (200 - len(':') - 32 - len(settings.IMAGEKIT_CACHE_PREFIX)),
         md5(
             force_bytes(
                 '%s%s-state' %
                 (settings.IMAGEKIT_CACHE_PREFIX, filename))).hexdigest()))
def test_memcached_cache_key():
    """
    Ensure the default cachefile backend is sanitizing its cache key for
    memcached by default.

    """

    class MockFile(object):
        def __init__(self, name):
            self.name = name

    backend = Simple()
    extra_char_count = len('state-') + len(settings.IMAGEKIT_CACHE_PREFIX)

    length = 199 - extra_char_count
    filename = '1' * length
    file = MockFile(filename)
    eq_(backend.get_key(file), '%s%s-state' %
        (settings.IMAGEKIT_CACHE_PREFIX, file.name))

    length = 200 - extra_char_count
    filename = '1' * length
    file = MockFile(filename)
    eq_(backend.get_key(file), '%s%s:%s' % (
        settings.IMAGEKIT_CACHE_PREFIX,
        '1' * (200 - len(':') - 32 - len(settings.IMAGEKIT_CACHE_PREFIX)),
        md5(force_bytes('%s%s-state' % (settings.IMAGEKIT_CACHE_PREFIX, filename))).hexdigest()))
Beispiel #3
0
 def test_non_existent_cached_image(self, img):
     """
     Test that the cached image does not exist before 'thumbnail_url' property method is called
     """
     self.assertFalse(Simple()._exists(
         self.curated_thumbnail.img_thumbnail))
Beispiel #4
0
 def test_cached_image_generation(self, img):
     """
     Test that the 'thumbnail_url' property method generates a new cached image
     """
     self.curated_thumbnail.thumbnail_url
     self.assertTrue(Simple()._exists(self.curated_thumbnail.img_thumbnail))