コード例 #1
0
ファイル: test_solutions.py プロジェクト: mrguz170/lms
    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_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
コード例 #3
0
    def test_get_next_unchecked(
        course: Course,
        student_user: User,
        exercise: Exercise,
        staff_user: User,
        _assessments,
    ):
        student_user2 = conftest.create_student_user(index=1)
        exercise2 = conftest.create_exercise(course, 2, index=3)
        solution1 = conftest.create_solution(exercise, student_user)
        solution2 = conftest.create_solution(exercise2, student_user)
        solution3 = conftest.create_solution(exercise, student_user2)

        assert len(list(Solution.select())) == 3

        unchecked = solutions.get_next_unchecked(exercise.id)
        assert unchecked is not None
        assert unchecked.exercise.id == solution1.exercise.id
        assert unchecked == solution1

        solutions.mark_as_checked(solution1.id, staff_user)
        unchecked = solutions.get_next_unchecked(exercise.id)
        assert unchecked is not None
        assert unchecked.exercise.id == solution3.exercise.id
        assert unchecked == solution3

        solutions.mark_as_checked(solution3.id, staff_user)
        unchecked = solutions.get_next_unchecked(exercise.id)
        assert unchecked is None

        unchecked = solutions.get_next_unchecked()
        assert unchecked is not None
        assert unchecked == solution2

        solutions.mark_as_checked(solution2.id, staff_user)
        unchecked = solutions.get_next_unchecked()
        assert unchecked is None

        unchecked = solutions.get_next_unchecked(solution2.id)
        assert unchecked is None
コード例 #4
0
ファイル: views.py プロジェクト: zoharb157/lms
def done_checking(exercise_id, solution_id):
    is_updated = solutions.mark_as_checked(solution_id, current_user.id)
    next_solution = solutions.get_next_unchecked(exercise_id)
    next_solution_id = getattr(next_solution, 'id', None)
    return jsonify({'success': is_updated, 'next': next_solution_id})
コード例 #5
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