예제 #1
0
    def test_get_thumbnail(self):
        source_name = 'image'
        self.backend.add_source(source_name)
        self.backend.add_thumbnail(source_name, 'small', 'image_small')
        self.assertEqual(self.backend.get_thumbnail(source_name, 'small'), ImageMeta(source_name, 'image_small', 'small'))
        self.backend.add_thumbnail(source_name, 'large', 'image_large')

        self.assertEqual(
            self.backend.get_thumbnails(source_name),
            [
                ImageMeta(source_name, 'image_small', 'small'),
                ImageMeta(source_name, 'image_large', 'large')
            ]
        )
예제 #2
0
    def test_get_thumbnail(self):
        source_name = 'image.jpg'
        self.backend.add_source(source_name)
        self.backend.add_thumbnail(source_name, 'small', 'image_small.jpg')
        self.assertEqual(self.backend.get_thumbnail(source_name, 'small'),
                         ImageMeta(source_name, 'image_small.jpg', 'small'))
        self.backend.add_thumbnail(source_name, 'large', 'image_large.jpg')
        self.backend.add_thumbnail(source_name, 'source_with_format',
                                   'image_source_with_format.webp')

        self.assertEqual(self.backend.get_thumbnails(source_name), [
            ImageMeta(source_name, 'image_small.jpg', 'small'),
            ImageMeta(source_name, 'image_large.jpg', 'large'),
            ImageMeta(source_name, 'image_source_with_format.webp',
                      'source_with_format')
        ])
예제 #3
0
    def test_get_thumbnail(self):
        source_name = 'test-thumbnail.jpg'

        self.backend.add_source(source_name)
        self.backend.add_thumbnail(source_name, 'small',
                                   'test-thumbnail_small.jpg')
        self.assertEqual(
            self.backend.get_thumbnail(source_name, 'small'),
            ImageMeta(source_name, 'test-thumbnail_small.jpg', 'small'))
        self.backend.add_thumbnail(source_name, 'large',
                                   'test-thumbnail_large.jpg')

        expected = ['test-thumbnail_large.jpg', 'test-thumbnail_small.jpg']
        result = [
            image_meta.name
            for image_meta in self.backend.get_thumbnails(source_name)
        ]
        # sort is replacing the variable in place, not returning new value, it will always return None
        result.sort()
        expected.sort()
        self.assertEqual(result, expected)

        # Delete Source & Thumbnails
        thumbnail_key = self.backend.get_thumbnail_key(source_name)
        self.redis.hdel(self.backend.get_source_key(source_name), source_name)
        self.redis.hdel(thumbnail_key, 'small')
        self.redis.hdel(thumbnail_key, 'large')
예제 #4
0
    def test_get_thumbnail(self):
        source_name = 'test-thumbnail.jpg'

        self.backend.add_source(source_name)
        self.backend.add_thumbnail(source_name, 'small', 'test-thumbnail_small.jpg')
        self.assertEqual(self.backend.get_thumbnail(source_name, 'small'), ImageMeta(source_name, 'test-thumbnail_small.jpg', 'small'))
        self.backend.add_thumbnail(source_name, 'large', 'test-thumbnail_large.jpg')

        expected = ['test-thumbnail_large.jpg', 'test-thumbnail_small.jpg']
        result = [image_meta.name for image_meta in self.backend.get_thumbnails(source_name)]
        self.assertEqual(result.sort(), expected.sort())

        # Delete Source & Thumbnails
        thumbnail_key = self.backend.get_thumbnail_key(source_name)
        self.redis.hdel(self.backend.get_source_key(source_name), source_name)
        self.redis.hdel(thumbnail_key, 'small')
        self.redis.hdel(thumbnail_key, 'large')