Created
November 11, 2014 21:32
-
-
Save cameronwp/41ed84d02eee97d2b22c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gateways/evalutations.py | |
@ndb.tasklet | |
def executeAndEvaluate(self, submission, node, calling_url=None): | |
"""Wrapper for chaining execution and evaluation with conditional behavior. | |
Args: | |
submission: The submission to execute and evaluate | |
node: The content node for the submission | |
calling_url: The path used by a calling Action, if applicable. For logging only | |
Returns: | |
A tuple (execution, evaluation) containing the results, permission permitting. | |
""" | |
# Manually check whether the evaluator is accessible instead of putting the processing and | |
# evaluation inside a warden property permission enforcement context. | |
node.guard.checkAllowedProperty('read', content.EvaluatedNode.evaluator) | |
# If this person has node edit permission and is trying to grade, bypass any masking | |
can_regrade_submissions = node.guard.isAllowed('regrade') | |
if submission.is_for_evaluation: | |
submission.operation = (evaluation.SUBMISSION_REGRADE | |
if can_regrade_submissions else evaluation.SUBMISSION_GRADE) | |
execution = yield node.process(submission, calling_url) | |
evaluate = None | |
if submission.is_for_evaluation: | |
# Void the execution for students, as it contains grading information | |
evaluate = yield node.evaluate(submission, execution, calling_url) | |
# If there's an error with the grading script, show error_details in classroom to staff | |
is_staff = node.guard.isAllowed('staff') | |
if is_staff and evaluate.error_details: | |
evaluate.comment = evaluate.error_details | |
execution = execution if can_regrade_submissions else None | |
raise ndb.Return((execution, evaluate)) | |
tests/gateways/test_evaluations.py | |
def testErrorDetailsShownToStaff(self): | |
self.simple_grading = """ | |
grade_result['correct'] = bug | |
grade_result['completed'] = False | |
grade_result['comment'] = 'Freeform' | |
""" | |
self.evaluator = evaluation.CodeGradedEvaluator(gae_grading_code=self.simple_grading) | |
self.assignment = content.ProgrammingQuiz(evaluator=self.evaluator) | |
self.assignment.guard.allow(self.STAFF_ACCOUNT.key, 'view') | |
self.submission = evaluation.Submission(parts=[], operation='GRADE') | |
self.resetSession(self.STAFF_ACCOUNT) | |
(execution, evaluate) = self.gateway.executeAndEvaluate( | |
self.submission, self.assignment).get_result() | |
self.assertIsNone(execution) | |
self.assertIsNotNone(evaluate) | |
self.assertIn(evaluate.error_details, evaluate.comment) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment