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
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, )
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')
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})
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)