def test_thumbnail_creation(self): data = 'big_image_data' compressed_data = 'cmprsd_data' image = Image.create(data=data) mock_service_image = mock() when(images).Image(blob_key=image.blob_key).thenReturn(mock_service_image) when(mock_service_image).execute_transforms(output_encoding = images.JPEG).thenReturn(compressed_data) options = Options(dict(width=420)) thumbnail = Image.thumbnail(image.short_key, options) verify(mock_service_image).resize(width=420) self.assertEqual(compressed_data, read_blob(thumbnail.blob_key)) self.assertEqual(thumbnail.key, key.Key(Image, options.key, parent = image.key)) original_blob_key = thumbnail.blob_key thumbnail = Image.thumbnail(image.short_key, options) self.assertEqual(original_blob_key, thumbnail.blob_key)
def thumbnail(self): return Image.thumbnail(self.key, self.options)