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
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']
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