def _process_video(self): granulate = Granulate() grains = granulate.granulate(str(self.filename), decodestring(self._video)) grains_keys = {'images':[], 'videos':[], 'audio':None, 'thumbnails':None, 'converted_video':None} if grains.has_key('image_list'): for image in grains['image_list']: encoded_image = { 'filename':image.id, 'file':b64encode(image.getContent().getvalue()), 'description':image.description } image_key = self.sam.post(value=encoded_image).resource().key grains_keys['images'].append(image_key) if grains.has_key('file_list'): for video in grains['file_list']: encoded_video = { 'filename':video.id, 'file':b64encode(video.getContent().getvalue()) } video_key = self.sam.post(value=encoded_video).resource().key grains_keys['videos'].append(video_key) if grains.has_key('audio') and grains['audio'] is not None: audio = grains['audio'] print 'Got the video audio.' row = {'file': b64encode(audio.getContent().getvalue()), 'filename': 'audio.oga'} audio_key = self.sam.post(value=row).resource().key grains_keys['audio'] = audio_key if grains.has_key('thumbnails') and grains['thumbnails'] is not None: thumbnails = [thumbnail for thumbnail in grains['thumbnails']] print 'Got the video thumbnails.' grains_keys['thumbnails'] = [] for thumbnail in thumbnails: row = {'file': b64encode(thumbnail.getContent().getvalue())} thumbnail_key = self.sam.post(value=row).resource().key grains_keys['thumbnails'].append(thumbnail_key) if grains.has_key('converted_video') and grains['converted_video'] is not None: converted_video = grains['converted_video'] print 'Got the converted video.' row = {'file': b64encode(converted_video.getContent().getvalue()), 'filename': converted_video.id} converted_video_key = self.sam.post(value=row).resource().key grains_keys['converted_video'] = converted_video_key self.grains_keys = grains_keys del grains del granulate
def _process_video(self): granulate = Granulate() grains = granulate.granulate(str(self.filename), decodestring(self._video)) grains_keys = {'images':[], 'videos':[]} if grains.has_key('image_list'): for image in grains['image_list']: encoded_image = { 'filename':image.id, 'file':b64encode(image.getContent().getvalue()), 'description':image.description } image_key = self.sam.put(value=encoded_image).resource().key grains_keys['images'].append(image_key) if grains.has_key('file_list'): for video in grains['file_list']: encoded_video = { 'filename':video.id, 'file':b64encode(video.getContent().getvalue()) } video_key = self.sam.put(value=encoded_video).resource().key grains_keys['videos'].append(video_key) self.grains_keys = grains_keys del grains
class TestGranulate(unittest.TestCase): def setUp(self): self.granController = Granulate(host=ServerOoodhost, port=ServerOoodport) def testGranulate(self): """ This test passes arguments the old way. """ t1 = time.time() dictFile = getFileDirList() for k, v in dictFile.iteritems(): resultDict = self.granController.granulate(filename=k, data=v) self.assertEquals(len(resultDict['image_list']), FileInfo[k][0]) self.assertEquals(len(resultDict['file_list']), FileInfo[k][1]) print " \n File: "+ k + '\n Time run method: ' + str((time.time() -t1)/(24*3600)) def testGetTableDocumentList(self): """ This test passes arguments the old way. """ t1 = time.time() dictFile = getFileDirList() for k, v in dictFile.iteritems(): resultList = self.granController.getTableDocumentList(filename=k, data=v) self.assertEquals(len(resultList), FileInfo[k][1]) print " \n File: "+ k + '\n Time run method: ' + str((time.time() -t1)/(24*3600)) def testGetImageDocumentList(self): """ This test passes arguments the old way. """ t1 = time.time() dictFile = getFileDirList() for k, v in dictFile.iteritems(): resultList = self.granController.getImageDocumentList(filename=k, data=v) self.assertEquals(len(resultList), FileInfo[k][0]) print " \n File: "+ k + '\n Time run method: ' + str((time.time() -t1)/(24*3600)) def testGetThumbnailsDocument(self): """ This test passes arguments the old way. """ t1 = time.time() dictFile = getFileDirList() for k, v in dictFile.iteritems(): result = self.granController.getThumbnailsDocument(filename=k, data=v) self.failUnless(result is not None) #self.assertEquals(resultDict['thumbnails'], is instance) print " \n File: "+ k + '\n Time run method: ' + str((time.time() -t1)/(24*3600)) def testGetSummaryDocument(self): """ This test passes arguments the old way. """ t1 = time.time() dictFile = getFileDirList() for k, v in dictFile.iteritems(): resultList = self.granController.getSummaryDocument(filename=k, data=v) self.assertFalse(bool(resultList)) print " \n File: "+ k + '\n Time run method: ' + str((time.time() -t1)/(24*3600)) def testGettingImagesFromDocx(self): images = self.granController.getImageDocumentList(data=DOCX_DATA, filename='file.docx') self.assertEquals(len(images), 27) self.assertEquals(FIRST_DOCX_IMAGE, images[0].getvalue()) def testGettingImagesFromPptx(self): images = self.granController.getImageDocumentList(data=PPTX_DATA, filename='file.pptx') self.assertEquals(len(images), 1) self.assertEquals(FIRST_PPTX_IMAGE, images[0].getvalue()) def testGettingThumbnailsFromDocx(self): thumbnails_docx = self.granController.getThumbnailsDocument(data=THREE_TABLES_DOCX_DATA, filename='three_tables.docx') self.assertEquals(thumbnails_docx.getvalue(), THUMBNAILS_DOCX_DATA) def testGettingThumbnailsFromPptx(self): thumbnails_pptx = self.granController.getThumbnailsDocument(data=TWO_TABLES_PPTX_DATA, filename='two_tables.pptx') self.assertEquals(thumbnails_pptx.getvalue(), THUMBNAILS_PPTX_DATA)