Example #1
0
    def _clone_solution_comments(
        from_solution: models.Solution,
        to_solution: models.Solution,
    ) -> None:
        user_comments = models.Comment.by_solution(
            from_solution.id, ).filter(~models.Comment.is_auto)
        for comment in user_comments:
            models.Comment.create_comment(
                commenter=models.User.get_system_user(),
                line_number=comment.line_number,
                comment_text=comment.comment,
                file=to_solution.solution_files.get(),
                is_auto=True,
            )

        to_solution.checker = from_solution.checker
        to_solution.state = from_solution.state
        to_solution.save()
        notifications.send(
            kind=notifications.NotificationKind.CHECKED,
            user=to_solution.solver,
            related_id=to_solution,
            message=_(
                'הפתרון שלך לתרגיל %(subject)s נבדק.',
                subject=to_solution.exercise.subject,
            ),
            action_url=f'{routes.SOLUTIONS}/{to_solution.id}',
        )
Example #2
0
 def test_valid_solution(self, solution: models.Solution):
     solution.json_data_str = VALID_CODE
     solution.save()
     tasks.run_flake8_on_solution(solution.id)
     comments = tuple(
         models.Comment.filter(models.Comment.solution == solution))
     assert not comments
Example #3
0
 def test_pyflake_wont_execute_code(self, solution: models.Solution):
     solution.json_data_str = self.execute_script
     solution.save()
     tasks.run_flake8_on_solution(solution.id)
     comments = tuple(
         models.Comment.filter(models.Comment.solution == solution))
     assert not os.listdir(self.test_directory)
     assert len(comments) == 2
     exec(compile(self.execute_script, '', 'exec'))  # noqa S102
     assert os.listdir(self.test_directory) == ['some-file']
Example #4
0
 def test_invalid_solution(self, solution: models.Solution):
     solution.json_data_str = INVALID_CODE
     solution.save()
     tasks.run_flake8_on_solution(solution.id)
     comments = tuple(
         models.Comment.filter(models.Comment.solution == solution))
     assert comments
     assert len(comments) == 1
     comment = comments[0].comment
     assert comment.text == INVALID_CODE_MESSAGE
     assert comment.flake8_key == INVALID_CODE_KEY
     user_notifications = notifications.get_notifications_for_user(
         for_user=solution.solver)
     assert len(user_notifications) == 1
     assert user_notifications
     parameters = user_notifications[0]['message_parameters']
     subject = parameters['exercise_name']
     errors = parameters['errors']
     assert solution.exercise.subject == subject
     assert 1 == errors
Example #5
0
    def _clone_solution_comments(
        from_solution: models.Solution,
        to_solution: models.Solution,
    ) -> None:
        user_comments = models.Comment.by_solution(
            from_solution.id, ).filter(~models.Comment.is_auto)
        for comment in user_comments:
            models.Comment.create_comment(
                commenter=models.User.get_system_user(),
                line_number=comment.line_number,
                comment_text=comment.comment.comment_id,
                solution=to_solution,
                is_auto=True,
            )

        to_solution.checker = from_solution.checker
        to_solution.state = from_solution.state
        to_solution.save()
        notifications.create_notification(
            notification_type=(
                notifications.SolutionCheckedNotification.notification_type()),
            for_user=to_solution.solver,
            solution=to_solution,
        )