def on_start(submission_uuid): """ Creates a new student training workflow. This function should be called to indicate that a submission has entered the student training workflow part of the assessment process. Args: submission_uuid (str): The submission UUID for the student that is initiating training. Returns: None Raises: StudentTrainingInternalError: Raised when an error occurs persisting the Student Training Workflow """ try: StudentTrainingWorkflow.create_workflow(submission_uuid) except Exception as ex: msg = ( "An internal error has occurred while creating the learner " "training workflow for submission UUID {}".format(submission_uuid) ) logger.exception(msg) raise StudentTrainingInternalError(msg) from ex
def on_start(submission_uuid): """ Creates a new student training workflow. This function should be called to indicate that a submission has entered the student training workflow part of the assessment process. Args: submission_uuid (str): The submission UUID for the student that is initiating training. Returns: None Raises: StudentTrainingInternalError: Raised when an error occurs persisting the Student Training Workflow """ try: StudentTrainingWorkflow.create_workflow(submission_uuid) except Exception: msg = ( u"An internal error has occurred while creating the student " u"training workflow for submission UUID {}".format(submission_uuid) ) logger.exception(msg) raise StudentTrainingInternalError(msg)
def test_create_workflow_integrity_error(self, mock_create, mock_get): # Simulate a race condition in which someone creates a workflow # after we check if it exists. This will violate the database uniqueness # constraints, so we need to handle this case gracefully. mock_create.side_effect = IntegrityError # The first time we check, we should see that no workflow exists. # The second time, we should get the workflow created by someone else mock_workflow = mock.MagicMock(StudentTrainingWorkflow) mock_get.side_effect = [mock_workflow] # Expect that we retry and retrieve the workflow that someone else created submission = sub_api.create_submission(STUDENT_ITEM, ANSWER) StudentTrainingWorkflow.create_workflow(submission['uuid']) workflow = StudentTrainingWorkflow.get_workflow(submission['uuid']) self.assertEqual(workflow, mock_workflow)
def test_create_workflow_integrity_error(self, mock_create, mock_get): # Simulate a race condition in which someone creates a workflow # after we check if it exists. This will violate the database uniqueness # constraints, so we need to handle this case gracefully. mock_create.side_effect = IntegrityError # The first time we check, we should see that no workflow exists. # The second time, we should get the workflow created by someone else mock_workflow = mock.MagicMock(StudentTrainingWorkflow) mock_get.side_effect = [ mock_workflow ] # Expect that we retry and retrieve the workflow that someone else created submission = sub_api.create_submission(STUDENT_ITEM, ANSWER) StudentTrainingWorkflow.create_workflow(submission['uuid']) workflow = StudentTrainingWorkflow.get_workflow(submission['uuid']) self.assertEqual(workflow, mock_workflow)
def test_update_peer_workflow(self): submission = sub_api.create_submission(ITEM_1, ANSWER_1) workflow = workflow_api.create_workflow(submission["uuid"], ["training", "peer"]) StudentTrainingWorkflow.create_workflow( submission_uuid=submission["uuid"]) requirements = { "training": { "num_required": 2 }, "peer": { "must_grade": 5, "must_be_graded_by": 3 } } workflow_keys = set(workflow.keys()) self.assertEqual( workflow_keys, { 'submission_uuid', 'status', 'created', 'modified', 'score', 'assessment_score_priority' }) self.assertEqual(workflow["submission_uuid"], submission["uuid"]) self.assertEqual(workflow["status"], "training") peer_workflows = list( PeerWorkflow.objects.filter(submission_uuid=submission["uuid"])) self.assertFalse(peer_workflows) workflow_from_get = workflow_api.get_workflow_for_submission( submission["uuid"], requirements) del workflow_from_get['status_details'] self.assertEqual(workflow, workflow_from_get) requirements["training"]["num_required"] = 0 workflow = workflow_api.update_from_assessments( submission["uuid"], requirements) # New step is Peer, and a Workflow has been created. self.assertEqual(workflow["status"], "peer") peer_workflow = PeerWorkflow.objects.get( submission_uuid=submission["uuid"]) self.assertIsNotNone(peer_workflow)
def test_update_peer_workflow(self): submission = sub_api.create_submission(ITEM_1, "Shoot Hot Rod") workflow = workflow_api.create_workflow(submission["uuid"], ["training", "peer"], ON_INIT_PARAMS) StudentTrainingWorkflow.create_workflow(submission_uuid=submission["uuid"]) requirements = { "training": { "num_required": 2 }, "peer": { "must_grade": 5, "must_be_graded_by": 3 } } workflow_keys = set(workflow.keys()) self.assertEqual( workflow_keys, { 'override_score', 'submission_uuid', 'uuid', 'status', 'created', 'modified', 'score' } ) self.assertEqual(workflow["submission_uuid"], submission["uuid"]) self.assertEqual(workflow["status"], "training") peer_workflows = list(PeerWorkflow.objects.filter(submission_uuid=submission["uuid"])) self.assertFalse(peer_workflows) workflow_from_get = workflow_api.get_workflow_for_submission( submission["uuid"], requirements ) del workflow_from_get['status_details'] self.assertEqual(workflow, workflow_from_get) requirements["training"]["num_required"] = 0 workflow = workflow_api.update_from_assessments(submission["uuid"], requirements) # New step is Peer, and a Workflow has been created. self.assertEqual(workflow["status"], "peer") peer_workflow = PeerWorkflow.objects.get(submission_uuid=submission["uuid"]) self.assertIsNotNone(peer_workflow)
def test_create_workflow_item_integrity_error(self, mock_create): # Create a submission and workflow submission = sub_api.create_submission(STUDENT_ITEM, ANSWER) workflow = StudentTrainingWorkflow.create_workflow(submission['uuid']) # Simulate a race condition in which someone creates a workflow item # after we check if it exists. mock.MagicMock(StudentTrainingWorkflowItem) mock_create.side_effect = IntegrityError # Expect that we retry and retrieve the workflow item created by someone else self.assertEqual(workflow.next_training_example(EXAMPLES), EXAMPLES[0])
def test_create_workflow_item_integrity_error(self, mock_create): # Create a submission and workflow submission = sub_api.create_submission(STUDENT_ITEM, ANSWER) workflow = StudentTrainingWorkflow.create_workflow(submission['uuid']) # Simulate a race condition in which someone creates a workflow item # after we check if it exists. mock_workflow_item = mock.MagicMock(StudentTrainingWorkflowItem) mock_create.side_effect = IntegrityError # Expect that we retry and retrieve the workflow item created by someone else self.assertEqual(workflow.next_training_example(EXAMPLES), EXAMPLES[0])