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
Ejemplo n.º 2
0
def add_video_by_competition(request):
    if request.method == 'POST':
        print("Llego al servicio y se revisa llegada de id competition")
        competition_id = request.POST.get('competition_id')
        new_video = Video(
            name=request.POST.get('name'),
            surname=request.POST.get('surname'),
            state=False,
            user_email=request.POST.get('user_email'),
            message=request.POST.get('message'),
            original_video=request.FILES['original_video'],
            uploadDate=datetime.datetime.now(),
            competition=Competition.objects.filter(id=competition_id).get())

        new_video.save()

        return JsonResponse({'ok': 'video guardado'}, status=200)
Ejemplo n.º 3
0
class TestHelper(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)

    def tearDown(self):
        db.session.remove()
        db.drop_all()
class TestService(unittest.TestCase):

    def setUp(self):
        app.config['TESTING'] = True
        app.config['CSRF_ENABLED'] = False
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + TEST_DB_PATH
        self.client = 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_id = self.video.id
        self.comment = Comment('Text', self.video.id, self.user.id)
        self.comment.save()
        self.anonuser = Device()
        self.anonuser2 = Device()
        self.room = Room('roomname', self.anonuser.id)
        self.room.save(self.video.id)

    def tearDown(self):
        db.session.remove()
        db.drop_all()

    def test_should_logout_page_be_exist(self):
        response = self.client.get("/logout", follow_redirects=True)
        self.assertEqual(response.status_code, 200)

    def test_is_askNewComm_work(self):
        response = self.client.get("/askNewComm/" + str(self.video.id), follow_redirects=True)
        self.assertEqual(response.status_code, 200)

    def test_is_getNewComm_work(self):
        response = self.client.get("/getNewComm/" + str(self.video.id) + '/' + str(self.comment.id),
                                   follow_redirects=True)
        self.assertEqual(response.status_code, 200)

    def test_is_likeVideo_work(self):
        response = self.client.get("/likeVideo/" + str(self.video.id), follow_redirects=True)
        self.assertEqual(response.status_code, 200)

    def test_is_dislikeVideo_work(self):
        response = self.client.get("/dislikeVideo/" + str(self.video.id), follow_redirects=True)
        self.assertEqual(response.status_code, 200)