def test_file_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_addFile('file', 'File', data) 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) # The file have been replaced with a ghost asset to the original one. self.assertEqual(self.root.ghost._getOb('file'), result) self.assertTrue(verifyObject(IGhostAsset, result)) self.assertEqual(result.get_link_status(), None) self.assertEqual(result.get_haunted(), self.root.folder.file) self.assertEqual(result.get_mime_type(), 'image/png') self.assertEqual(result.get_filename(), 'file.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 test_service(self): """Test service implementation. """ service = getUtility(IFilesService) self.assertEquals(self.root.service_files, service) self.assertTrue(verifyObject(IFilesService, service)) service.storage = File.ZODBFile zodb_file = service.new_file('test') self.assertTrue(IZODBFile.providedBy(zodb_file)) self.assertTrue(service.is_file_using_correct_storage(zodb_file)) service.storage = File.BlobFile blob_file = service.new_file('test') self.assertTrue(IBlobFile.providedBy(blob_file)) self.assertFalse(IZODBFile.providedBy(blob_file)) self.assertTrue(service.is_file_using_correct_storage(blob_file)) self.assertFalse(service.is_file_using_correct_storage(zodb_file)) # You can only add a service file in a local site. factory = self.root.folder.manage_addProduct['Silva'] with self.assertRaises(BadRequest): factory.manage_addFilesService('service_files')
def assertIsBlobFile(self, content): self.assertTrue(IBlobFile.providedBy(content))
def assertIsBlobImage(self, content): self.assertTrue(IImage.providedBy(content)) self.assertTrue(IBlobFile.providedBy(content.hires_image))
def validate(self, content): if IBlobFile.providedBy(content): return False return IFile.providedBy(content)