def save_video(video_file, title): ext = secure_filename(video_file.filename).split('.')[-1] video_hash = md5(video_file.read()).hexdigest() video_file.seek(0) video = Video(title) video.save(video_hash, cur_user()) videos.save(video_file, folder=str(video.id), name='video.' + ext) video.add_path(join_path(app.config['VIDEO_SAVE_PATH'], video.id)) try: prepare_video(video.id, ext) except OSError: video.delete_video() return None return video
class BaseTestModelSuite(unittest.TestCase): def setUp(self): app.config['TESTING'] = True app.config['CSRF_ENABLED'] = False app.config['DEBUG'] = False app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join( BASE_DIR, TEST_DB) self.app = app.test_client() db.create_all() self.user = User('TestUser') self.user.save('testpassword') self.video = Video('TestVideo') self.video.save(hash='Teststring', user=self.user) self.video.add_path( join_path(app.config['VIDEO_SAVE_PATH'], self.video.id)) def tearDown(self): db.session.remove() db.drop_all()