Commit bac7e995 by muzaffaryousaf

Adding the test for assessing cancelled sub.

Minor code refactoring.

TNL-900
parent 387521a4
......@@ -956,8 +956,8 @@ def cancel_submission_peer_workflow(submission_uuid, comments, cancelled_by_id):
Args:
submission_uuid (str): The UUID of the peer workflow's submission.
comments: The reason for cancellation.
cancelled_by_id: The ID of the user who cancelled the peer workflow.
comments (str): The reason for cancellation.
cancelled_by_id (str): The ID of the user who cancelled the peer workflow.
"""
try:
workflow = PeerWorkflow.objects.get(submission_uuid=submission_uuid)
......@@ -983,14 +983,8 @@ def get_submission_cancellation(submission_uuid):
submission_uuid (str): The UUID of the peer workflow's submission.
"""
try:
workflow = PeerWorkflow.objects.get(submission_uuid=submission_uuid)
workflow_cancellation = workflow.cancellations.latest('created_at')
return PeerWorkflowCancellationSerializer(workflow_cancellation).data
except (
PeerWorkflow.DoesNotExist,
PeerWorkflowCancellation.DoesNotExist,
):
return None
workflow_cancellation = PeerWorkflowCancellation.get_latest_workflow_cancellation(submission_uuid=submission_uuid)
return PeerWorkflowCancellationSerializer(workflow_cancellation).data if workflow_cancellation else None
except DatabaseError:
error_message = u"Error finding peer workflow cancellation for submission UUID {}.".format(submission_uuid)
logger.exception(error_message)
......
......@@ -521,3 +521,17 @@ class PeerWorkflowCancellation(models.Model):
'cancelled_by_id': cancelled_by_id,
}
return cls.objects.create(**cancellation_params)
@classmethod
def get_latest_workflow_cancellation(cls, submission_uuid):
"""
Get the latest PeerWorkflowCancellation for a submission's workflow.
Args:
submission_uuid (str): The UUID of the peer workflow's submission.
Returns:
PeerWorkflowCancellation or None
"""
workflow_cancellations = cls.objects.filter(workflow__submission_uuid=submission_uuid).order_by("-created_at")
return workflow_cancellations[0] if workflow_cancellations.exists() else None
......@@ -893,6 +893,47 @@ class TestPeerApi(CacheResetTest):
item = buffy_workflow.find_active_assessments()
self.assertIsNone(item)
@raises(peer_api.PeerAssessmentWorkflowError)
def test_assess_the_cancelled_submission(self):
# This will assess the pulled out submission to assess.
buffy_sub, buffy = self._create_student_and_submission("Buffy", "Buffy's answer")
xander_sub, xander = self._create_student_and_submission("Xander", "Xander's answer")
# Check for a workflow for Buffy.
buffy_workflow = PeerWorkflow.get_by_submission_uuid(buffy_sub['uuid'])
self.assertIsNotNone(buffy_workflow)
# Buffy is going to review Xander's submission, so create a workflow
# item for Buffy.
PeerWorkflow.create_item(buffy_workflow, xander_sub["uuid"])
# Check to see if Buffy is actively reviewing Xander's submission.
item = buffy_workflow.find_active_assessments()
self.assertEqual(xander_sub["uuid"], item.submission_uuid)
# Cancel the Xander's submission.
xander_workflow = PeerWorkflow.get_by_submission_uuid(xander_sub['uuid'])
PeerWorkflowCancellation.create(
workflow=xander_workflow, comments='Cancellation reason', cancelled_by_id=buffy['student_id']
)
# Check to see if Buffy is actively reviewing Xander's submission.
# She isn't able to get the submission to assess.
item = buffy_workflow.find_active_assessments()
self.assertIsNone(item)
# Try to assess the cancelled submission
# This will raise PeerAssessmentWorkflowError
peer_api.create_assessment(
buffy_sub['uuid'],
buffy["student_id"],
ASSESSMENT_DICT['options_selected'],
ASSESSMENT_DICT['criterion_feedback'],
ASSESSMENT_DICT['overall_feedback'],
RUBRIC_DICT,
REQUIRED_GRADED_BY,
)
def test_get_workflow_by_uuid(self):
buffy_answer, _ = self._create_student_and_submission("Buffy", "Buffy's answer")
self._create_student_and_submission("Xander", "Xander's answer")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment