def test_05_get_with_search(self): course = Course.add({ "name": "Curso de teste", "expires_at": "2020-11-20" }) course = Course.add({"name": "Batata", "expires_at": "4020-12-10"}) courses = Course.get_by_filter("Batata") assert len(courses) == 1 and courses[0]['name'] == "Batata"
def test_06_get_with_multiple_word_search(self): course = Course.add({ "name": "Fisioterapia para velhinhos", "expires_at": "2020-11-20" }) course = Course.add({"name": "Batata", "expires_at": "4020-12-10"}) courses = Course.get_by_filter("Fisioterapia%20velhinhos") assert len(courses) == 1 and courses[0][ 'name'] == "Fisioterapia para velhinhos"
def test_05_get_active(self): course = Course.add({ "name": "Curso de teste", "expires_at": "2020-11-20" }) course = Course.add({ "name": "Curso de teste 2", "expires_at": "4020-12-10" }) courses = Course.get_by_filter("active") assert len(courses) == 1 and courses[0]['name'] == "Curso de teste 2"
def test_07_update_data_fail(self): course = Course.add({"name": "Curso de teste"}) updated_course = Course.update_data( 2, {"name": "Curso de teste atualizado"}) updated_course_2 = Course.update_data( 1, {"error": "Curso de teste não atualizado"}) assert updated_course is None and updated_course_2 is None
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
def test_03_get_all(self): course = Course.add({"name": "Curso de teste"}) courses = Course.get_by_filter("all") assert list(courses[0].keys()) == [ 'id', 'name', 'number_of_videos', 'duration', 'price', 'is_watchable' ]
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'
def courses(filter): if request.method == 'POST': json_args = request.form['json_args'] result = json.loads(json_args) while type(result) == str: result = json.loads(result) if request.files: thumbnail = request.files.get('thumbnail') result['thumbnail'] = thumbnail.read() if is_valid_admin(request): course = Course.add(result) if course: course_dict = course.as_dict() response = jsonify(course_dict) response.status_code = 200 return response return error_response('Falha na adição do curso', 500) else: return error_response('Permissão negada', 401) elif request.method == 'GET': courses = Course.get_by_filter(filter) if courses is not None: response = jsonify(courses) response.status_code = 200 return response return error_response('Não foi possível recuperar os cursos', 500)
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
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 })
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
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
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"
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
def test_2_enroll_fail(self): course = Course.add({'name': 'Curso 1'}) user = User.register(email='*****@*****.**', password='******') attends = Attends.add(3, {'course_id': 3}) assert attends is None
def test_1_enroll(self): course = Course.add({'name': 'Curso 1'}) user = User.register(email='*****@*****.**', password='******') attends = Attends.add(1, {'course_id': 1, 'is_paid': False}) assert attends is not None and attends.user_id == 1 and attends.course.name == 'Curso 1'
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
def test_02_add_fail(self): course = Course.add({"error": "fail"}) assert course is None
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
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
def test_01_add(self): course = Course.add({"name": "Curso de teste"}) assert course is not None