Пример #1
0
def upload(request):
    
    feedback = {} #sera usado para o retorno da acao
    
    if request.is_ajax() or request.method == 'POST':        
        form = VideoForm(request.POST, request.FILES)
        video = Video(file = request.FILES['file'])
        video.formato = request.POST['formato']
        video.save()
        job = video.schedule_zencoder_job()
        
        if job.code == 201:
            feedback["status"] = "201" 
            feedback["job_id"] = job.body['id']
            feedback["video_id"] = video.id
            video.job_id = job.body['id']
            video.save()
        else:
            feedback["status"] = "422"
            feedback["job_id"] = "0"
        
        return HttpResponse(simplejson.dumps(feedback), mimetype="application/json")
    else:
        form = VideoForm()

    feedback["status"] = "nok"
    feedback["job_id"] = "0"
    
    return HttpResponse(simplejson.dumps(feedback), mimetype="application/json")
Пример #2
0
def upload(request):

    feedback = {}  #sera usado para o retorno da acao

    if request.is_ajax() or request.method == 'POST':
        form = VideoForm(request.POST, request.FILES)
        video = Video(file=request.FILES['file'])
        video.formato = request.POST['formato']
        video.save()
        job = video.schedule_zencoder_job()

        if job.code == 201:
            feedback["status"] = "201"
            feedback["job_id"] = job.body['id']
            feedback["video_id"] = video.id
            video.job_id = job.body['id']
            video.save()
        else:
            feedback["status"] = "422"
            feedback["job_id"] = "0"

        return HttpResponse(simplejson.dumps(feedback),
                            mimetype="application/json")
    else:
        form = VideoForm()

    feedback["status"] = "nok"
    feedback["job_id"] = "0"

    return HttpResponse(simplejson.dumps(feedback),
                        mimetype="application/json")
Пример #3
0
class SimpleTest(TestCase):
    """
     Testando o response da index
    """ 
    def test_index(self):
        resp = self.client.get('/')
        self.assertEqual(resp.status_code, 200)
    
    """
     Testando criar um video
    """
    def test_criar_video(self):
        self.video = Video(formato = 'WEBM', file = "%stestes/video_teste.mp4" % settings.MEDIA_URL)
        self.video.save()
        self.assertNotEqual(self.video.id, 0)
        self.assertEqual(self.video.formato, 'WEBM')
        self.assertEqual(self.video.file.name, "%stestes/video_teste.mp4" % settings.MEDIA_URL)
    
    """
     Testando o retorno de um job enviado para o zencoder
    """
    def test_job_zencoder(self):
        self.video = Video(formato = 'webm', file = "%stestes/video_teste.mp4" % settings.MEDIA_URL)
        self.video.save()
        self.job = self.video.schedule_zencoder_job()
        self.assertNotEqual(self.job.body['id'], 0)
        self.assertEqual(self.job.code, 201)
        self.assertEqual(self.job.body['outputs'][0]['url'], "http://nandotorres.s3.amazonaws.com/video_teste.mp4.webm")        
Пример #4
0
def add_video():
    form = VideoForm()
    if form.validate_on_submit():
        video = Video(description=form.description.data, url=form.url.data)
        video.save()
        return redirect(url_for('main.videos'))
    return render_template('admin/add_video.html', form=form)