Beispiel #1
0
    def test_new_solution_override_old_solutions(
        self,
        exercise: Exercise,
        student_user: User,
    ):
        first_solution = conftest.create_solution(exercise, student_user)
        second_solution = conftest.create_solution(exercise, student_user)
        assert second_solution.state == self.created_state
        assert first_solution.refresh().state == self.old_solution_state

        next_unchecked = Solution.next_unchecked()
        assert next_unchecked is not None
        assert next_unchecked.id == second_solution.id
        next_unchecked = Solution.next_unchecked_of(exercise.id)
        assert next_unchecked is not None
        assert next_unchecked.id == second_solution.id
        assert next_unchecked.start_checking()
        assert next_unchecked.refresh().state == self.in_checking_state

        assert Solution.next_unchecked() is None
        assert Solution.next_unchecked_of(exercise.id) is None

        general_tasks.reset_solution_state_if_needed(second_solution.id)
        next_unchecked = Solution.next_unchecked()
        next_unchecked_by_id = Solution.next_unchecked_of(exercise.id)
        assert next_unchecked is not None and next_unchecked_by_id is not None
        assert next_unchecked.id == second_solution.id
        assert next_unchecked_by_id.id == second_solution.id
Beispiel #2
0
    def test_new_solution_override_old_solutions(
        self,
        exercise: Exercise,
        student_user: User,
    ):
        first_solution = conftest.create_solution(exercise, student_user)
        second_solution = conftest.create_solution(exercise, student_user)
        assert second_solution.state == self.created_state
        assert first_solution.refresh().state == self.old_solution_state

        next_unchecked = Solution.next_unchecked()
        assert next_unchecked is not None
        assert next_unchecked.id == second_solution.id
        next_unchecked = Solution.next_unchecked_of(exercise.id)
        assert next_unchecked is not None
        assert next_unchecked.id == second_solution.id
        assert next_unchecked.start_checking()
        assert next_unchecked.refresh().state == self.in_checking_state

        assert Solution.next_unchecked() is None
        assert Solution.next_unchecked_of(exercise.id) is None

        general_tasks.reset_solution_state_if_needed(second_solution.id)
        next_unchecked = Solution.next_unchecked()
        next_unchecked_by_id = Solution.next_unchecked_of(exercise.id)
        assert next_unchecked is not None and next_unchecked_by_id is not None
        assert next_unchecked.id == second_solution.id
        assert next_unchecked_by_id.id == second_solution.id

        third_solution = conftest.create_solution(
            exercise,
            student_user,
            code='123',
        )
        fourth_solution = conftest.create_solution(
            exercise,
            student_user,
            code='1234',
        )
        assert not Solution.is_duplicate(
            third_solution.hashed,
            student_user,
            exercise,
            already_hashed=True,
        )
        assert Solution.is_duplicate(
            fourth_solution.hashed,
            student_user,
            exercise,
            already_hashed=True,
        )
Beispiel #3
0
    def test_next_exercise_with_cleanest_code(
        self,
        comment: Comment,
        staff_user: User,
    ):
        student_user: User = conftest.create_student_user(index=1)
        first_solution = comment.solution
        comment_text = comment.comment
        second_solution = conftest.create_solution(comment.solution.exercise,
                                                   student_user)

        # comment exists on first solution - second one should be the first
        next_unchecked = Solution.next_unchecked()
        assert next_unchecked is not None
        assert next_unchecked.id == second_solution.id

        # delete the comment should give us back the first solution
        Comment.delete_by_id(comment.id)
        next_unchecked = Solution.next_unchecked()
        assert next_unchecked is not None
        assert next_unchecked.id == first_solution.id

        # if second_solution has comments we should get first solution
        Comment.create_comment(
            commenter=staff_user,
            line_number=1,
            comment_text=comment_text,
            file=second_solution.solution_files.get(),
            is_auto=False,
        )
        next_unchecked = Solution.next_unchecked()
        assert next_unchecked is not None
        assert next_unchecked.id == first_solution.id

        # both have comments - the first one should be the first solution
        Comment.create_comment(
            commenter=staff_user,
            line_number=1,
            comment_text=comment_text,
            file=first_solution.solution_files.get(),
            is_auto=False,
        )
        next_unchecked = Solution.next_unchecked()
        assert next_unchecked is not None
        assert next_unchecked.id == first_solution.id
Beispiel #4
0
def start_checking(exercise_id):
    if exercise_id != 0:
        next_exercise = Solution.next_unchecked_of(exercise_id)
    else:
        next_exercise = Solution.next_unchecked()
    if next_exercise and next_exercise.start_checking():
        general_tasks.reset_solution_state_if_needed.apply_async(
            args=(next_exercise.id, ),
            countdown=Solution.MAX_CHECK_TIME_SECONDS,
        )
        return redirect(f'/view/{next_exercise.id}')
    return redirect('/exercises')
Beispiel #5
0
    def test_manager_reset_state_expect_exceptions(
        solution: Solution,
        caplog: pytest.LogCaptureFixture,
    ):
        reset = general_tasks.reset_solution_state_if_needed
        assert reset(solution.id) is None
        assert 'does not exist' not in caplog.text
        next_unchecked = Solution.next_unchecked()
        assert next_unchecked
        next_unchecked.start_checking()
        assert reset(solution.id) is None
        assert 'does not exist' not in caplog.text

        solution_id_that_does_not_exists = 1234567890
        with pytest.raises(models.Solution.DoesNotExist):
            assert reset(solution_id_that_does_not_exists) is None
        assert 'does not exist' in caplog.text
Beispiel #6
0
def get_next_unchecked(exercise_id: int = 0) -> Optional[Solution]:
    if exercise_id == 0:
        return Solution.next_unchecked()
    return Solution.next_unchecked_of(exercise_id)