Example #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
Example #2
0
 def test_invalid_solution(self, solution: 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(Comment.by_solution(solution))
     assert comments
     assert len(comments) == 1
     assert comments[0].comment.text == INVALID_CODE_MESSAGE
Example #3
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']
Example #4
0
 def test_invalid_solution(self, solution: 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(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
Example #5
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