Esempio n. 1
0
 def test_03_get_videos_as_dict(self):
     course = Course.add({'name': "Curso de Teste"})
     course = Course.get_by_id(1)
     video = Video.add(1, {'youtube_code': 'test_code', 'course_order': 1})
     videos = course.get_videos_as_dict()
     assert list(videos[0].keys()) == ['id', 'youtube_code', 'title', \
         'description', 'duration', 'thumbnail', 'course_order'] and videos[0]['youtube_code'] == 'test_code'
Esempio n. 2
0
 def test_04_get_by_id(self):
     course = Course.add({'name': 'Curso de Teste'})
     user = User.register('*****@*****.**', '12345678')
     video = Video.add(1, {'title': 'Video 1'})
     watches = Watches.add(1, 1)
     watches = Watches.get_by_ids(1, 1)
     assert watches is not None
Esempio n. 3
0
def videos(id):
    course = Course.get_by_id(id)
    if course is None:
        return {}, 404

    if request.method == 'GET':
        videos = course.get_videos_as_dict()
        response = jsonify(videos)
        response.status_code = 200
        return response

    elif request.method == 'POST':
        if is_valid_admin(request):
            request_video = {}
            if request.files:
                upload_succeded, video = upload_video(request.files['video'],
                                                      request.form)
                if upload_succeded:
                    info = video['snippet']
                    request_video = {
                        'youtube_code': video['id'],
                        'title': info['title'],
                        'description': info['description'],
                        'thumbnail': info['thumbnails']['high']['url'],
                        'duration': request.form['duration'],
                        'course_order': int(request.form['course_order'])
                    }
            else:
                request_video = request.get_json()
            video = Video.add(id, request_video)
            if video:
                return {}, 200
            return error_response('Vídeo não adicionado', 500)
        return error_response('Permissão negada', 401)
Esempio n. 4
0
 def test_03_as_dict(self):
     course = Course.add({'name': 'Curso de Teste'})
     user = User.register('*****@*****.**', '12345678')
     video = Video.add(1, {'title': 'Video 1'})
     watches = Watches.add(1, 1)
     watches_dict = watches.as_dict()
     assert list(watches_dict.keys()) == ['user_id', 'video_id', 'watched_time', 'finished'] and \
         watches_dict['finished'] == False
Esempio n. 5
0
 def test_07_update_fail(self):
     course = Course.add({'name': 'Curso de Teste'})
     user = User.register('*****@*****.**', '12345678')
     video = Video.add(1, {'title': 'Video 1'})
     watches = Watches.add(1, 1)
     updated = Watches.update_data(1, 1, {
         'watched_time': 200,
         'finish': False
     })
Esempio n. 6
0
 def test_06_update_data(self):
     course = Course.add({'name': 'Curso de Teste'})
     user = User.register('*****@*****.**', '12345678')
     video = Video.add(1, {'title': 'Video 1'})
     watches = Watches.add(1, 1)
     updated = Watches.update_data(1, 1, {
         'watched_time': 200,
         'finished': True
     })
     assert updated.finished == True and updated.watched_time == 200
Esempio n. 7
0
 def test_04_get_by_id(self):
     course = Course.add({'name': "Curso de Teste"})
     video = Video.add(1, {'youtube_code': 'test_code', 'course_order': 1})
     new_video = Video.get_by_id(1)
     video_fail = Video.get_by_id(2)
     assert new_video is not None and new_video.id == video.id and video_fail is None
Esempio n. 8
0
 def test_02_add_fail(self):
     video = Video.add(2, {'youtube_code': 'test_code', 'course_order': 1})
     assert video is None
Esempio n. 9
0
 def test_01_add(self):
     course = Course.add({'name': "Curso de Teste"})
     video = Video.add(1, {'youtube_code': 'test_code', 'course_order': 1})
     assert video is not None