def _set_team_staff_score(self, score): reason = "A staff member has defined the score for this submission" sub_team_api.set_score(self.team_submission_uuid, score["points_earned"], score["points_possible"], annotation_creator=score["staff_id"], annotation_type=self.STAFF_ANNOTATION_TYPE, annotation_reason=reason)
def test_set_score_error(self, mock_log): """ Test for when there is an error creating one individual score. No scores should be created. """ mock_log.side_effect = [None, None, None, Exception()] team_submission = self._make_team_submission(create_submissions=True) with self.assertRaises(Exception): team_api.set_score(team_submission.uuid, 6, 10) self.assertFalse( Score.objects.filter( submission__team_submission=team_submission).exists())
def test_reset_scores(self, set_scores, clear_state): """ Test for resetting scores. """ team_submission = self._make_team_submission(create_submissions=True) if set_scores: team_api.set_score(team_submission.uuid, 6, 10) team_submission.refresh_from_db() self.assertEqual(team_submission.status, ACTIVE) student_items = [] for submission in team_submission.submissions.all(): self.assertEqual(submission.status, ACTIVE) student_items.append(submission.student_item) # We have no / some scores, and no resets. self.assertEqual( Score.objects.filter(student_item__in=student_items, reset=False).count(), 0 if not set_scores else len(student_items) ) self.assertEqual( Score.objects.filter(student_item__in=student_items, reset=True).count(), 0 ) # Reset team_api.reset_scores(team_submission.uuid, clear_state=clear_state) expected_state = DELETED if clear_state else ACTIVE # If we've cleared the state, the team submission status should be DELETED, # as should all of the individual submissions team_submission.refresh_from_db() self.assertEqual(team_submission.status, expected_state) for submission in team_submission.submissions.all(): self.assertEqual(submission.status, expected_state) # We have created reset scores self.assertEqual( Score.objects.filter(student_item__in=student_items, reset=True).count(), len(student_items) )
def test_set_score(self): """ Test that calling team_api.set_score will set the score for each individual submission, and that calling it again will create another score for all individual submissions. """ team_submission = self._make_team_submission(create_submissions=True) team_api.set_score(team_submission.uuid, 6, 10) first_round_scores = {} for student_id in self.student_ids: individual_submission = team_submission.submissions.get( student_item__student_id=student_id) self.assertEqual(individual_submission.score_set.count(), 1) score = individual_submission.score_set.first() self.assertEqual(score.points_earned, 6) self.assertEqual(score.points_possible, 10) self.assertFalse(score.scoreannotation_set.exists()) first_round_scores[student_id] = score team_api.set_score( team_submission.uuid, 9, 10, annotation_creator='some_staff', annotation_reason='they did some extra credit!', annotation_type='staff_override', ) for student_id in self.student_ids: individual_submission = team_submission.submissions.get( student_item__student_id=student_id) self.assertEqual(individual_submission.score_set.count(), 2) second_score = individual_submission.score_set.exclude( pk=first_round_scores[student_id].pk).first() self.assertEqual(second_score.points_earned, 9) self.assertEqual(second_score.points_possible, 10) self.assertEqual(second_score.scoreannotation_set.count(), 1) annotation = second_score.scoreannotation_set.first() self.assertEqual(annotation.creator, 'some_staff') self.assertEqual(annotation.reason, 'they did some extra credit!') self.assertEqual(annotation.annotation_type, 'staff_override')