def test_get_num_completed_num_queries(self): # Complete the first training example training_api.get_training_example(self.submission_uuid, RUBRIC, EXAMPLES) training_api.assess_training_example(self.submission_uuid, EXAMPLES[0]['options_selected']) # Check the number completed with self.assertNumQueries(2): training_api.get_num_completed(self.submission_uuid)
def _assert_workflow_status(self, submission_uuid, num_completed, num_required): """ Check that the training workflow is on the expected step. Args: submission_uuid (str): Submission UUID of the student being trained. num_completed (int): The expected number of examples assessed correctly. num_total (int): The required number of examples to assess. Returns: None Raises: AssertionError """ # Check the number of steps we've completed actual_num_completed = training_api.get_num_completed(submission_uuid) self.assertEqual(actual_num_completed, num_completed) # Check whether the assessment step is completed # (used by the workflow API) requirements = {'num_required': num_required} is_finished = training_api.submitter_is_finished( submission_uuid, requirements) self.assertEqual(is_finished, bool(num_completed >= num_required))
def _assert_workflow_status(self, submission_uuid, num_completed, num_required): """ Check that the training workflow is on the expected step. Args: submission_uuid (str): Submission UUID of the student being trained. num_completed (int): The expected number of examples assessed correctly. num_total (int): The required number of examples to assess. Returns: None Raises: AssertionError """ # Check the number of steps we've completed actual_num_completed = training_api.get_num_completed(submission_uuid) self.assertEqual(actual_num_completed, num_completed) # Check whether the assessment step is completed # (used by the workflow API) requirements = {'num_required': num_required} is_finished = training_api.submitter_is_finished(submission_uuid, requirements) self.assertEqual(is_finished, bool(num_completed >= num_required)) # Assessment is finished should always be true, # since we're not being assessed by others. self.assertTrue(training_api.assessment_is_finished(submission_uuid, requirements)) # At no point should we receive a score! self.assertIs(training_api.get_score(submission_uuid, requirements), None)
def training_path_and_context(self): """ Return the template path and context used to render the student training step. Returns: tuple of `(path, context)` where `path` is the path to the template and `context` is a dict. """ # Retrieve the status of the workflow. # If no submissions have been created yet, the status will be None. workflow_status = self.get_workflow_info().get('status') problem_closed, reason, start_date, due_date = self.is_closed( step="student-training") context = {} template = 'openassessmentblock/student_training/student_training_unavailable.html' # add allow_latex field to the context context['allow_latex'] = self.allow_latex if not workflow_status: return template, context # If the student has completed the training step, then show that the step is complete. # We put this condition first so that if a student has completed the step, it *always* # shows as complete. # We're assuming here that the training step always precedes the other assessment steps # (peer/self) -- we may need to make this more flexible later. if workflow_status == 'cancelled': template = 'openassessmentblock/student_training/student_training_cancelled.html' elif workflow_status and workflow_status != "training": template = 'openassessmentblock/student_training/student_training_complete.html' # If the problem is closed, then do not allow students to access the training step elif problem_closed and reason == 'start': context['training_start'] = start_date template = 'openassessmentblock/student_training/student_training_unavailable.html' elif problem_closed and reason == 'due': context['training_due'] = due_date template = 'openassessmentblock/student_training/student_training_closed.html' # If we're on the training step, show the student an example # We do this last so we can avoid querying the student training API if possible. else: training_module = self.get_assessment_module('student-training') if not training_module: return template, context if due_date < DISTANT_FUTURE: context['training_due'] = due_date # Report progress in the student training workflow (completed X out of Y) context['training_num_available'] = len( training_module["examples"]) context[ 'training_num_completed'] = student_training.get_num_completed( self.submission_uuid) context[ 'training_num_current'] = context['training_num_completed'] + 1 # Retrieve the example essay for the student to submit # This will contain the essay text, the rubric, and the options the instructor selected. examples = convert_training_examples_list_to_dict( training_module["examples"]) example = student_training.get_training_example( self.submission_uuid, { 'prompt': self.prompt, 'criteria': self.rubric_criteria_with_labels }, examples) if example: context['training_essay'] = create_submission_dict( {'answer': example['answer']}, self.prompts) context['training_rubric'] = { 'criteria': example['rubric']['criteria'], 'points_possible': example['rubric']['points_possible'] } template = 'openassessmentblock/student_training/student_training.html' else: logger.error( "No training example was returned from the API for student " "with Submission UUID {}".format(self.submission_uuid)) template = "openassessmentblock/student_training/student_training_error.html" return template, context
def training_path_and_context(self): """ Return the template path and context used to render the student training step. Returns: tuple of `(path, context)` where `path` is the path to the template and `context` is a dict. """ # Retrieve the status of the workflow. # If no submissions have been created yet, the status will be None. workflow_status = self.get_workflow_info().get('status') problem_closed, reason, start_date, due_date = self.is_closed(step="student-training") context = {} template = 'openassessmentblock/student_training/student_training_unavailable.html' # add allow_latex field to the context context['allow_latex'] = self.allow_latex if not workflow_status: return template, context # If the student has completed the training step, then show that the step is complete. # We put this condition first so that if a student has completed the step, it *always* # shows as complete. # We're assuming here that the training step always precedes the other assessment steps # (peer/self) -- we may need to make this more flexible later. if workflow_status == 'cancelled': template = 'openassessmentblock/student_training/student_training_cancelled.html' elif workflow_status and workflow_status != "training": template = 'openassessmentblock/student_training/student_training_complete.html' # If the problem is closed, then do not allow students to access the training step elif problem_closed and reason == 'start': context['training_start'] = start_date template = 'openassessmentblock/student_training/student_training_unavailable.html' elif problem_closed and reason == 'due': context['training_due'] = due_date template = 'openassessmentblock/student_training/student_training_closed.html' # If we're on the training step, show the student an example # We do this last so we can avoid querying the student training API if possible. else: training_module = self.get_assessment_module('student-training') if not training_module: return template, context if due_date < DISTANT_FUTURE: context['training_due'] = due_date # Report progress in the student training workflow (completed X out of Y) context['training_num_available'] = len(training_module["examples"]) context['training_num_completed'] = student_training.get_num_completed(self.submission_uuid) context['training_num_current'] = context['training_num_completed'] + 1 # Retrieve the example essay for the student to submit # This will contain the essay text, the rubric, and the options the instructor selected. examples = convert_training_examples_list_to_dict(training_module["examples"]) example = student_training.get_training_example( self.submission_uuid, { 'prompt': self.prompt, 'criteria': self.rubric_criteria_with_labels }, examples ) if example: context['training_essay'] = create_submission_dict({'answer': example['answer']}, self.prompts) context['training_rubric'] = { 'criteria': example['rubric']['criteria'], 'points_possible': example['rubric']['points_possible'] } template = 'openassessmentblock/student_training/student_training.html' else: logger.error( "No training example was returned from the API for student " "with Submission UUID {}".format(self.submission_uuid) ) template = "openassessmentblock/student_training/student_training_error.html" return template, context
def test_get_num_completed_database_error(self, mock_db): mock_db.side_effect = DatabaseError("Kaboom!") with self.assertRaises(StudentTrainingInternalError): training_api.get_num_completed(self.submission_uuid)
def test_get_num_completed_no_workflow(self): num_completed = training_api.get_num_completed(self.submission_uuid) self.assertEqual(num_completed, 0)