def test_transcode_2tasks_delete1(db, cds_depid, mock_sorenson): """Test TranscodeVideoTask task when run 2 task and delete 1.""" def get_bucket_keys(): return [o.key for o in list(ObjectVersion.get_by_bucket(bucket))] bucket = deposit_project_resolver(cds_depid).files.bucket filesize = 1024 filename = 'test.mp4' preset_qualities = ['480p', '720p'] new_filenames = ['{0}.mp4'.format(p) for p in preset_qualities] (version_id, [task_s1, task_s2]) = transcode_task(bucket=bucket, filesize=filesize, filename=filename, preset_qualities=preset_qualities) assert get_bucket_keys() == [filename] assert bucket.size == filesize # Transcode task_s1.delay(deposit_id=cds_depid) task_s2.delay(deposit_id=cds_depid) db.session.add(bucket) keys = get_bucket_keys() assert len(keys) == 3 assert new_filenames[0] in keys assert new_filenames[1] in keys assert filename in keys assert bucket.size == (3 * filesize) # Undo TranscodeVideoTask().clean(version_id=version_id, preset_quality=preset_qualities[0]) db.session.add(bucket) keys = get_bucket_keys() assert len(keys) == 2 assert new_filenames[0] not in keys assert new_filenames[1] in keys assert filename in keys assert bucket.size == (3 * filesize)
def test_transcode_ignore_exception_if_invalid(db, bucket): """Test ignore exception if sorenson raise InvalidResolutionError.""" def get_bucket_keys(): return [o.key for o in list(ObjectVersion.get_by_bucket(bucket))] filesize = 1024 filename = 'test.mp4' preset_qualities = ['480p', '720p'] (version_id, [task_s1, task_s2]) = transcode_task( bucket=bucket, filesize=filesize, filename=filename, preset_qualities=preset_qualities) assert get_bucket_keys() == [filename] assert bucket.size == filesize with mock.patch('cds.modules.webhooks.tasks.start_encoding', side_effect=InvalidResolutionError('fuu', 'test')): # Transcode task = task_s1.delay() isinstance(task.result, Ignore)