Example #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'
Example #2
0
def course(id):
    course = Course.get_by_id(id)
    if course is None:
        return {}, 404
    if request.method == 'GET':
        course_dict = course.as_dict()
        response = jsonify(course_dict)
        response.status_code = 200
        return response
    if is_valid_admin(request):
        if request.method == 'PUT':
            json_args = request.form['json_args']
            result = json.loads(json_args)
            while type(result) == str:
                result = json.loads(result)
            course = Course.update_data(id, result)
            if course:
                course_dict = course.as_dict()
                response = jsonify(course_dict)
                response.status_code = 200
                return response
            else:
                return error_response('Curso não atualizado', 500)

        elif request.method == 'DELETE':
            if Course.delete(id):
                return {}, 200
            else:
                return error_response(
                    'Curso não deletado. Tente novamente em alguns minutos.',
                    500)
    else:
        return error_response('Permissão negada', 401)
Example #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)
Example #4
0
 def test_09_delete_fail(self):
     course = Course.add({"name": "Curso de teste"})
     Course.delete(2)
     deleted_course = Course.get_by_id(1)
     assert deleted_course is not None
Example #5
0
 def test_08_delete(self):
     course = Course.add({"name": "Curso de teste"})
     is_deleted = Course.delete(1)
     deleted_course = Course.get_by_id(1)
     assert is_deleted == True and deleted_course is None
Example #6
0
 def test_06_update_data(self):
     course = Course.add({"name": "Curso de teste"})
     course = Course.update_data(1, {"name": "Curso de teste atualizado"})
     updated_course = Course.get_by_id(1)
     assert updated_course.name == "Curso de teste atualizado"
Example #7
0
 def test_04_get_by_id(self):
     course = Course.add({"name": "Curso de teste"})
     new_course = Course.get_by_id(1)
     fail_course = Course.get_by_id(2)
     assert new_course is not None and new_course.id == course.id and fail_course is None