def test_image_in_valid_ghost_folder_missing_original(self): factory = self.root.manage_addProduct['Silva'] factory.manage_addFolder('folder', 'Folder') factory.manage_addGhostFolder('ghost', None, haunted=self.root.folder) factory = self.root.folder.manage_addProduct['Silva'] factory.manage_addIndexer('image', 'Image') # This is not an image. factory = self.root.ghost.manage_addProduct['Silva'] factory.manage_addImage('image', 'Image') image = self.root.ghost._getOb('image') with self.layer.open_fixture('silva.png') as data: image.hires_image = Image('image', 'Image', data) self.assertFalse(IFile.providedBy(image.image)) self.assertFalse(IFile.providedBy(image.hires_image)) self.assertFalse(IFile.providedBy(image.thumbnail_image)) self.assertTrue(image_upgrader.validate(image)) result = image_upgrader.upgrade(image) self.assertEqual(result, image) # Image should have not been replaced, but have been updated. self.assertEqual(self.root.ghost._getOb('image'), result) self.assertTrue(verifyObject(IImage, result)) self.assertTrue(verifyObject(IFile, result.image)) self.assertTrue(verifyObject(IFile, result.hires_image)) self.assertTrue(verifyObject(IFile, result.thumbnail_image)) self.assertEqual(result.get_mime_type(), 'image/png') self.assertEqual(result.get_filename(), 'image.png')
def test_image_in_valid_ghost_folder(self): factory = self.root.manage_addProduct['Silva'] factory.manage_addFolder('folder', 'Folder') factory.manage_addGhostFolder('ghost', None, haunted=self.root.folder) factory = self.root.folder.manage_addProduct['Silva'] with self.layer.open_fixture('silva.png') as data: factory.manage_addImage('image', 'Image', data) factory = self.root.ghost.manage_addProduct['Silva'] factory.manage_addImage('image', 'Image') image = self.root.ghost._getOb('image') with self.layer.open_fixture('silva.png') as data: image.hires_image = Image('image', 'Image', data) self.assertFalse(IFile.providedBy(image.image)) self.assertFalse(IFile.providedBy(image.hires_image)) self.assertFalse(IFile.providedBy(image.thumbnail_image)) self.assertTrue(image_upgrader.validate(image)) result = image_upgrader.upgrade(image) self.assertNotEqual(result, image) # The image have been replaced with a ghost asset to the original one. self.assertEqual(self.root.ghost._getOb('image'), result) self.assertTrue(verifyObject(IGhostAsset, result)) self.assertEqual(result.get_link_status(), None) self.assertEqual(result.get_haunted(), self.root.folder.image) self.assertEqual(result.get_mime_type(), 'image/png') self.assertEqual(result.get_filename(), 'image.png')
def upgrade_to_ghost(self, content): container = content.get_container() if not IGhostFolder.providedBy(container): return None if container.get_link_status() is not None: logger.warning( u"Invalid Ghost Folder, not transforming: %s.", content_path(content)) return None file_id = content.getId() container_haunted = container.get_haunted() file_haunted = container_haunted._getOb(file_id, None) if not IFile.providedBy(file_haunted): logger.warning( u"Original found for %s, but is not an file, not transforming it.", content_path(content)) return None ghost = get_factory(file_haunted)( ghost=content, container=container, auto_delete=True, auto_publish=True).modify(file_haunted, file_id).verify() logger.info( u"File converted to ghost asset: %s.", content_path(content)) return ghost
def test_image(self): factory = self.root.manage_addProduct['Silva'] factory.manage_addImage('image', 'Image') image = self.root._getOb('image') with self.layer.open_fixture('silva.png') as data: image.hires_image = Image('image', 'Image', data) self.assertFalse(IFile.providedBy(image.image)) self.assertFalse(IFile.providedBy(image.hires_image)) self.assertFalse(IFile.providedBy(image.thumbnail_image)) self.assertTrue(image_upgrader.validate(image)) result = image_upgrader.upgrade(image) self.assertEqual(result, image) # Image is still here, and content have been replaced. self.assertTrue(verifyObject(IImage, result)) self.assertTrue(verifyObject(IFile, result.image)) self.assertTrue(verifyObject(IFile, result.hires_image)) self.assertTrue(verifyObject(IFile, result.thumbnail_image)) self.assertEqual(self.root._getOb('image'), result) self.assertEqual(result.get_mime_type(), 'image/png') self.assertEqual(result.get_filename(), 'image.png')
def test_file(self): factory = self.root.manage_addProduct['Silva'] with self.layer.open_fixture('silva.png') as data: factory.manage_addFile('file', 'File', data) data = self.root._getOb('file') self.assertTrue(IFile.providedBy(data)) self.assertFalse(IBlobFile.providedBy(data)) self.assertTrue(file_upgrader.validate(data)) result = file_upgrader.upgrade(data) self.assertNotEqual(result, data) self.assertTrue(verifyObject(IBlobFile, result)) self.assertEqual(self.root._getOb('file'), result) self.assertEqual(result.get_mime_type(), 'image/png') self.assertEqual(result.get_filename(), 'file.png')
def test_file_in_valid_ghost_folder_missing_original(self): factory = self.root.manage_addProduct['Silva'] factory.manage_addFolder('folder', 'Folder') factory.manage_addGhostFolder('ghost', None, haunted=self.root.folder) factory = self.root.folder.manage_addProduct['Silva'] factory.manage_addIndexer('file', 'File') # This is not a file. factory = self.root.ghost.manage_addProduct['Silva'] with self.layer.open_fixture('silva.png') as data: factory.manage_addFile('file', 'File', data) data = self.root.ghost._getOb('file') self.assertTrue(IFile.providedBy(data)) self.assertFalse(IBlobFile.providedBy(data)) self.assertTrue(file_upgrader.validate(data)) result = file_upgrader.upgrade(data) self.assertNotEqual(result, data) self.assertTrue(verifyObject(IBlobFile, result)) self.assertEqual(self.root.ghost._getOb('file'), result) self.assertEqual(result.get_mime_type(), 'image/png') self.assertEqual(result.get_filename(), 'file.png')
def validate(self, content): if IBlobFile.providedBy(content): return False return IFile.providedBy(content)