def test_good_values(self):
        image = FakeImage(image=RELATIVE_PIC_NAME, misc=1)
        image.save()

        basedir = getattr(settings, 'CUDDLYBUDDLY_THUMBNAIL_BASEDIR', '')
        subdir = getattr(settings, 'CUDDLYBUDDLY_THUMBNAIL_SUBDIR', '')
        tests = {
            '{% thumbnail "'+RELATIVE_PIC_NAME+'" 51 51 %}':
                ((basedir, subdir), 'cb-thumbnail-test_jpg_51x51_q85.jpg'),
            '{% thumbnail "'+RELATIVE_PIC_NAME+'" 52 52 50 %}':
                ((basedir, subdir), 'cb-thumbnail-test_jpg_52x52_q50.jpg'),
            '{% thumbnail "'+RELATIVE_PIC_NAME+'" 53 53 50 as thumb %}{{ thumb }}':
                ((basedir, subdir), 'cb-thumbnail-test_jpg_53x53_q50.jpg'),
            '{% thumbnail "'+RELATIVE_PIC_NAME+'" 54 54 None "cb-thumbnail-test_jpg_tag.jpg" %}':
                ('', 'cb-thumbnail-test_jpg_tag.jpg'),
            '{% thumbnail "'+RELATIVE_PIC_NAME+'" 54 54 90 "cb-thumbnail-test_jpg_tag2.jpg" %}':
                ('', 'cb-thumbnail-test_jpg_tag2.jpg'),
            '{% thumbnail source width height quality dest as thumb %}{{ thumb }}':
                ('', 'cb-thumbnail-test_jpg_templatevars.jpg', {
                    'source': RELATIVE_PIC_NAME,
                    'width': 66,
                    'height': 77,
                    'quality': 88,
                    'dest': 'cb-thumbnail-test_jpg_templatevars.jpg'
                }),
            '{% thumbnail source.image width height quality dest as thumb %}{{ thumb }}':
                ('', 'cb-thumbnail-test_jpg_field.jpg', {
                    'source': image,
                    'width': 67,
                    'height': 78,
                    'quality': 88,
                    'dest': 'cb-thumbnail-test_jpg_field.jpg'
                }),
        }
        for name, val in tests.items():
            if len(val) == 2:
                val = (val[0], val[1], {})
            if hasattr(val[0], '__iter__'):
                path = os.path.join(*val[0])
            else:
                path = val[0]
            path = os.path.join(path, val[1])
            cache = os.path.join(
                settings.CUDDLYBUDDLY_THUMBNAIL_CACHE,
                md5_constructor(smart_str(path)).hexdigest()
            )
            self.cache_to_delete.add(cache)
            path = path.replace('\\', '/')
            self.assertEqual(self.render_template(name, val[2]), path)
            self.assert_(default_storage.exists(path))
            self.images_to_delete.add(path)
        image.delete()
    def test_autodiscover(self):
        thumbnail.autodiscover()
        image = FakeImage(image=RELATIVE_PIC_NAME, misc=1)
        image.save()

        thumb = Thumbnail(image.image, 20, 15)
        self.verify_thumb(thumb, 20, 15, '20x15_q85.jpg')
        cache = os.path.join(
            settings.CUDDLYBUDDLY_THUMBNAIL_CACHE,
            md5_constructor(force_unicode(image.image)).hexdigest()
        )
        self.assert_(os.path.exists(cache), 'Does not exist: %s' % cache)
        self.cache_to_delete.add(cache)

        image.misc = 1
        image.save()
        self.assert_(not os.path.exists(cache), 'Should not exist: %s' % cache)

        thumb = Thumbnail(image.image, 20, 15)
        self.verify_thumb(thumb, 20, 15, '20x15_q85.jpg')
        self.assert_(os.path.exists(cache), 'Does not exist: %s' % cache)

        image.delete()
        self.assert_(not os.path.exists(cache), 'Should not exist: %s' % cache)