예제 #1
0
    def test_mark_as_checked(
        exercise: Exercise,
        student_user: User,
        staff_user: User,
        solution: Solution,
    ):
        # Basic functionality
        assert solution.state == Solution.STATES.CREATED.name
        marked = solutions.mark_as_checked(solution.id, staff_user.id)
        # HELL WITH PEEWEE!!!
        solution = Solution.get_by_id(solution.id)
        assert marked
        assert solution.state == Solution.STATES.DONE.name
        assert solution.checker == staff_user

        # Not duplicating things
        staff_user2 = conftest.create_staff_user(index=1)
        solution2 = conftest.create_solution(exercise, student_user)
        marked = solutions.mark_as_checked(solution2.id, staff_user2.id)
        solution2 = Solution.get_by_id(solution2.id)
        assert solution2.state == Solution.STATES.DONE.name
        assert solution2.checker == staff_user2

        # Creates notifications
        assert len(list(notifications.get(student_user))) == 2
예제 #2
0
    def test_solutions_of_user(
        staff_user: User,
        student_user: User,
        course: Course,
        solution: Solution,
        _assessments,
    ):
        conftest.create_usercourse(student_user, course)
        client = conftest.get_logged_user(staff_user.username)
        client.post(
            f'/assessment/{solution.id}',
            data=json.dumps({'assessment': 2}),
            content_type='application/json',
        )
        solution = Solution.get_by_id(solution.id)
        assert solution.assessment.name == 'Nice'

        client.post(
            f'/assessment/{solution.id}',
            data=json.dumps({'assessment': None}),
            content_type='application/json',
        )

        exercise2 = conftest.create_exercise(course, 2)
        solution2 = conftest.create_solution(exercise2, student_user)
        client.post(
            f'/assessment/{solution2.id}',
            data=json.dumps({'assessment': 3}),
            content_type='application/json',
        )
        solution2 = Solution.get_by_id(solution2.id)

        exercises = solution.of_user(student_user.id, from_all_courses=True)
        assert exercises[0].get('assessment') is None
        assert exercises[1].get('assessment') == 'Try again'
예제 #3
0
    def test_strange_solution_with_no_files(
        exercise: Exercise,
        student_user: User,
        staff_user: User,
    ):
        solution = conftest.create_solution(
            exercise,
            student_user,
            files=[],
            hash_='koko',
        )

        staff_client = conftest.get_logged_user(staff_user.username)
        view_response = staff_client.get(f'{routes.SOLUTIONS}/{solution.id}')
        assert view_response.status_code == 200
        solution = Solution.get_by_id(solution.id)
        assert solution.state == Solution.STATES.DONE.name

        to_show_in_view = {
            'solution': solution,
            'file_id': None,
            'shared_url': '',
            'is_manager': False,
            'solution_files': (),
            'viewer_is_solver': True,
        }

        with pytest.raises(ResourceNotFound):
            assert get_view_parameters(**to_show_in_view)

        user_client = conftest.get_logged_user(student_user.username)
        assert len(list(notifications.get(student_user))) == 1
        view_response = user_client.get(f'{routes.SOLUTIONS}/{solution.id}')
        assert view_response.status_code == 404
예제 #4
0
    def test_last_view_status(
        solution: Solution,
        student_user: User,
        staff_user: User,
    ):
        client = conftest.get_logged_user(student_user.username)
        assert solution.last_status_view == SolutionStatusView.UPLOADED.name

        client.get(f'/view/{solution.id}')
        solution = Solution.get_by_id(solution.id)
        assert solution.last_status_view == SolutionStatusView.NOT_CHECKED.name

        solutions.mark_as_checked(solution.id, staff_user.id)
        solution = Solution.get_by_id(solution.id)
        assert solution.last_status_view == SolutionStatusView.NOT_CHECKED.name
        client.get(f'/view/{solution.id}')
        solution = Solution.get_by_id(solution.id)
        assert solution.last_status_view == SolutionStatusView.CHECKED.name
예제 #5
0
def mark_as_checked(solution_id: int, checker_id: int) -> bool:
    checked_solution: Solution = Solution.get_by_id(solution_id)
    is_updated = checked_solution.mark_as_checked(by=checker_id)
    msg = f'הפתרון שלך לתרגיל "{checked_solution.exercise.subject}" נבדק.'
    if is_updated:
        notifications.send(
            kind=notifications.NotificationKind.CHECKED,
            user=checked_solution.solver,
            related_id=solution_id,
            message=msg,
            action_url=f'{routes.SOLUTIONS}/{solution_id}',
        )
    if config.FEATURE_FLAG_CHECK_IDENTICAL_CODE_ON:
        (identical_tests_tasks.check_if_other_solutions_can_be_solved.
         apply_async(args=(solution_id, )))
    return is_updated
예제 #6
0
    def test_start_checking(exercise: Exercise, student_user: User):
        student_user2 = conftest.create_student_user(index=1)
        exercise2 = conftest.create_exercise(1)
        solution1 = conftest.create_solution(exercise, student_user)
        solution2 = conftest.create_solution(exercise2, student_user)
        solution3 = conftest.create_solution(exercise, student_user2)

        is_checking = solutions.start_checking(solution=None)
        assert not is_checking

        with no_celery:
            for solution in (solution1, solution2, solution3):
                assert solution.state == Solution.STATES.CREATED.name
                is_checking = solutions.start_checking(solution=solution)
                assert is_checking
                the_solution = Solution.get_by_id(solution.id)
                assert the_solution.state == Solution.STATES.IN_CHECKING.name
예제 #7
0
파일: views.py 프로젝트: yaronneuman/lms
def done_checking(exercise_id, solution_id):
    checked_solution: Solution = Solution.get_by_id(solution_id)
    is_updated = checked_solution.set_state(new_state=Solution.STATES.DONE)
    if is_updated:
        notifications.create_notification(
            notification_type=(
                notifications.SolutionCheckedNotification.notification_type()),
            for_user=checked_solution.solver,
            solution=checked_solution,
        )
    identical_tests_tasks.check_if_other_solutions_can_be_solved.apply_async(
        args=(solution_id, ))
    next_exercise = None
    solution = Solution.next_unchecked_of(exercise_id)
    if solution and solution.start_checking():
        general_tasks.reset_solution_state_if_needed.apply_async(
            args=(solution.id, ),
            countdown=Solution.MAX_CHECK_TIME_SECONDS,
        )
        next_exercise = solution.id
    return jsonify({'success': is_updated, 'next': next_exercise})
예제 #8
0
def change_assessment(
    solution_id: int, assessment_id: Optional[int] = None,
) -> bool:
    checked_solution: Solution = Solution.get_by_id(solution_id)
    return checked_solution.change_assessment(assessment_id=assessment_id)
예제 #9
0
    def test_user_commented_after_check(
        solution: Solution,
        student_user: User,
        staff_user: User,
    ):
        client = conftest.get_logged_user(student_user.username)

        # Marking the solution as checked
        solutions.mark_as_checked(solution.id, staff_user.id)
        solution = Solution.get_by_id(solution.id)

        # Sending comments after solution checked
        comment_response = client.post('/comments',
                                       data=json.dumps({
                                           'fileId':
                                           solution.files[0].id,
                                           'act':
                                           'create',
                                           'kind':
                                           'text',
                                           'comment':
                                           'new one',
                                           'line':
                                           1,
                                       }),
                                       content_type='application/json')
        new_comment_response = client.post('/comments',
                                           data=json.dumps({
                                               'fileId':
                                               solution.files[0].id,
                                               'act':
                                               'create',
                                               'kind':
                                               'text',
                                               'comment':
                                               'another one',
                                               'line':
                                               2,
                                           }),
                                           content_type='application/json')
        assert comment_response.status_code == 200
        assert new_comment_response.status_code == 200
        assert len(list(notifications.get(staff_user))) == 1

        conftest.logout_user(client)
        client2 = conftest.get_logged_user(staff_user.username)

        # Sending a comment after student user commented
        staff_comment_response = client2.post(
            '/comments',
            data=json.dumps({
                'fileId': solution.files[0].id,
                'act': 'create',
                'kind': 'text',
                'comment': 'FINE',
                'line': 1,
            }),
            content_type='application/json',
        )
        assert staff_comment_response.status_code == 200
        assert len(list(notifications.get(student_user))) == 2

        conftest.logout_user(client2)
        client = conftest.get_logged_user(student_user.username)

        # User student comments again
        another_comment_response = client.post(
            '/comments',
            data=json.dumps({
                'fileId': solution.files[0].id,
                'act': 'create',
                'kind': 'text',
                'comment': 'OK',
                'line': 3,
            }),
            content_type='application/json',
        )
        assert another_comment_response.status_code == 200
        assert len(list(notifications.get(staff_user))) == 2