def test_on_video_deleted(self): # add a video to the system and create thumbnail testpath = os.path.dirname(__file__) path = os.path.join(testpath,'test_video.flv') video_data = open(path,'rb') self.videos_howto.invokeFactory('File', 'vid2', title='Vid2') self.vid2 = self.videos_howto._getOb('vid2') self.vid2.data=video_data.read() notify(ObjectModifiedEvent(self.vid2)) video_data.close() cFilter = {"portal_type" : "Image"} # 2 thumbnails that are in base.py self.assertEqual(len(self.videos_howto.getFolderContents(cFilter)),2) on_video_added(self.vid2, None) # assert that another thumbnail has been created self.assertEqual(len(self.videos_howto.getFolderContents(cFilter)),3) thumb = self.videos_howto.getFolderContents(cFilter)[2].getObject() self.assertEqual(thumb.id,'vid2-thumb') # delete the thumbnail of self.vid2 on_video_deleted(self.vid2, None) # thumbnail has been deleted - only 2 thumbnails remain self.assertEqual(len(self.videos_howto.getFolderContents(cFilter)),2) ref = [x.id for x in self.videos_howto.getFolderContents(cFilter)] self.assertEqual(ref,['vid1thumb','vid2thumb']) # self.vid2 has not been deleted because the eventhandler only deletes # the thumbnail self.assertEqual(self.videos_howto.getFolderContents()[2].getObject(), self.vid2)
def test_on_video_added(self): # supply a bad file and test for error status messages testpath = os.path.dirname(__file__) path = os.path.join(testpath,'test_fakevideo.flv') video_data = open(path,'rb') self.videos_howto.invokeFactory('File', 'vid1', title='Vid1') self.vid1 = self.videos_howto._getOb('vid1') self.vid1.data=video_data.read() notify(ObjectModifiedEvent(self.vid1)) video_data.close() on_video_added(self.vid1, None) test = IStatusMessage(self.request).show() self.assertEqual(test[0].type,'error') self.assertEqual(test[0].message,'Thumbnail generation failed') self.assertEqual(test[1].type,'info') # the last part of the error message should be # 'Invalid data found when processing input\n' # Before that it mentions a specific temporary file path self.assertEqual(test[1].message[-41:], 'Invalid data found when processing input\n') # test that thumbnail was correctly created from a supplied video file path = os.path.join(testpath,'test_video.flv') video_data = open(path,'rb') self.videos_howto.invokeFactory('File', 'vid2', title='Vid2') self.vid2 = self.videos_howto._getOb('vid2') self.vid2.data=video_data.read() notify(ObjectModifiedEvent(self.vid2)) video_data.close() cFilter = {"portal_type" : "Image"} # 2 thumbnails that are in base.py self.assertEqual(len(self.videos_howto.getFolderContents(cFilter)),2) on_video_added(self.vid2, None) #assert that another thumbnail has been created self.assertEqual(len(self.videos_howto.getFolderContents(cFilter)),3) thumb = self.videos_howto.getFolderContents(cFilter)[2].getObject() self.assertEqual(thumb.id,'vid2-thumb')