예제 #1
0
 def test_valid_solution(self, solution: Solution):
     solution_file = solution.solution_files.get()
     solution_file.code = VALID_CODE
     solution_file.save()
     tasks.run_linter_on_solution(solution.id)
     comments = tuple(Comment.by_solution(solution))
     assert not comments
예제 #2
0
 def test_valid_solution(self, solution: models.Solution):
     solution_file = solution.solution_files.get()
     solution_file.path = 'index.html'
     solution_file.code = VALID_CODE
     solution_file.save()
     tasks.run_linter_on_solution(solution.id)
     comments = tuple(models.Comment.by_solution(solution))
     assert not comments
예제 #3
0
 def test_invalid_solution(self, solution: models.Solution):
     solution_file = solution.solution_files.get()
     solution_file.path = 'sql.sql'
     solution_file.code = INVALID_CODE
     solution_file.save()
     tasks.run_linter_on_solution(solution.id)
     comments = tuple(models.Comment.by_solution(solution))
     assert comments
     assert len(comments) == 1
     assert comments[0].comment.text == INVALID_CODE_MESSAGE
예제 #4
0
 def test_pyflake_wont_execute_code(self, solution: Solution):
     solution_file = solution.solution_files.get()
     solution_file.code = self.execute_script
     solution_file.save()
     tasks.run_linter_on_solution(solution.id)
     comments = tuple(Comment.by_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']
예제 #5
0
 def test_invalid_solution(self, solution: models.Solution):
     solution_file = solution.solution_files.get()
     solution_file.path = 'index.html'
     solution_file.code = INVALID_CODE
     solution_file.save()
     tasks.run_linter_on_solution(solution.id)
     comments = tuple(models.Comment.by_solution(solution))
     assert comments
     assert len(comments) == 3
     comment_texts = {comment.comment.text for comment in comments}
     assert comment_texts == INVALID_CODE_MESSAGES
예제 #6
0
    def test_run_linters_expect_unknown_solution(
        solution: models.Solution,
        caplog: pytest.LogCaptureFixture,
    ):
        tasks.run_linter_on_solution(solution.id)
        assert 'does not exist' not in caplog.text
        assert 'failed to check' not in caplog.text

        nonexist_solution = 123456789
        with pytest.raises(models.Solution.DoesNotExist):
            tasks.run_linter_on_solution(nonexist_solution)
        assert 'does not exist' in caplog.text
        assert 'failed to check' not in caplog.text
예제 #7
0
 def test_invalid_solution(self, solution: Solution):
     solution_file = solution.solution_files.get()
     solution_file.code = INVALID_CODE
     solution_file.save()
     tasks.run_linter_on_solution(solution.id)
     comments = tuple(Comment.by_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(user=solution.solver)
     assert len(user_notifications) == 1
     assert user_notifications
     subject = user_notifications[0].message
     assert solution.exercise.subject in subject
     assert '1' in subject