def test_get_all_team_submissions_for_course_item_error(self, mocked_qs): mocked_qs.side_effect = Exception() with self.assertRaises(TeamSubmissionInternalError): TeamSubmission.get_all_team_submissions_for_course_item( self.default_course_id, self.default_item_id, )
def test_get_team_submission_by_course_item_team_nonexistant(self): with self.assertRaises(TeamSubmissionNotFoundError): TeamSubmission.get_team_submission_by_course_item_team( self.other_course_id, self.other_item_id, 'some_other_team', )
def get_team_submission_for_team(course_id, item_id, team_id): """ Returns a single team submission (serialized) for the given team in the given (course, item). Raises: - TeamSubmissionNotFoundError when no such team submission exists. - TeamSubmissionInternalError if there is some other error looking up the team submission. """ team_submission = TeamSubmission.get_team_submission_by_course_item_team( course_id, item_id, team_id) return TeamSubmissionSerializer(team_submission).data
def get_team_submission(team_submission_uuid): """ Returns a single, serialized, team submission for the given key. Raises: - TeamSubmissionNotFoundError when no such team submission exists. - TeamSubmissionInternalError if there is some other error looking up the team submission. """ team_submission = TeamSubmission.get_team_submission_by_uuid( team_submission_uuid) return TeamSubmissionSerializer(team_submission).data
def get_all_team_submissions(course_id, item_id): """ Returns all of the (active) team submissions (serialized) in the given (course, item). Returns an empty iterable if no team submissions exist for this (course, item). Raises: - TeamSubmissionInternalError if there is some other error looking up the team submission. """ team_submissions = TeamSubmission.get_all_team_submissions_for_course_item( course_id, item_id) return TeamSubmissionSerializer(team_submissions, many=True).data
def get_team_submission_for_student(student_item_dict): """ Returns a single team submission (serialized). Looks up the team submission with an associated individual submission with the given student info. Raises: - TeamSubmissionNotFoundError when no such team submission exists. - TeamSubmissionInternalError if there is some other error looking up the team submission. """ student_item = _api._get_or_create_student_item(student_item_dict) # pylint: disable=protected-access team_submission = TeamSubmission.get_team_submission_by_student_item( student_item) return TeamSubmissionSerializer(team_submission).data
def reset_scores(team_submission_uuid, clear_state=False): """ Reset scores for a specific team submission to a problem. Note: this does *not* delete `Score` models from the database, since these are immutable. It simply creates a new score with the "reset" flag set to True. Args: team_submission_uuid (str): The uuid for the team submission for which to reset scores. clear_state (bool): If True, soft delete the team submission and any individual submissions by setting their status to DELETED Returns: None Raises: TeamSubmissionInternalError: An unexpected error occurred while resetting scores. """ # Get the team submission try: team_submission = TeamSubmission.get_team_submission_by_uuid( team_submission_uuid) for submission in team_submission.submissions.select_related( 'student_item').all(): _api.reset_score( submission.student_item.student_id, submission.student_item.course_id, submission.student_item.item_id, clear_state=clear_state, ) if clear_state: # soft-delete the TeamSubmission team_submission.status = DELETED team_submission.save(update_fields=["status"]) except (DatabaseError, SubmissionInternalError) as error: msg = ( f"Error occurred while reseting scores for team submission {team_submission_uuid}" ) logger.exception(msg) raise TeamSubmissionInternalError(msg) from error else: logger.info("Score reset for team submission %(team_submission_uuid)s", { 'team_submission_uuid': team_submission_uuid, })
def test_get_all_team_submissions_for_course_item(self): team_submission_1 = self.create_team_submission( self.user, team_id='another_team_1') team_submission_2 = self.create_team_submission( self.user, team_id='another_team_2') team_submission_3 = self.create_team_submission( self.user, team_id='another_team_3') self.create_team_submission(self.user, item_id=self.other_item_id, team_id='another_team_4') self.create_team_submission(self.user, course_id=self.other_course_id, team_id='another_team_another_course') result = TeamSubmission.get_all_team_submissions_for_course_item( self.default_course_id, self.default_item_id) self.assertEqual(len(result), 4) self.assertIn(self.default_submission, result) self.assertIn(team_submission_1, result) self.assertIn(team_submission_2, result) self.assertIn(team_submission_3, result)
def test_get_all_team_submissions_for_course_item_no_results(self): result = TeamSubmission.get_all_team_submissions_for_course_item( self.other_course_id, self.other_item_id) self.assertEqual(len(result), 0)
def test_get_team_submission_by_course_item_team(self): team_submission = TeamSubmission.get_team_submission_by_course_item_team( self.default_course_id, self.default_item_id, self.default_team_id) self.assertEqual(team_submission.id, self.default_submission.id)
def test_get_team_submission_by_uuid_error(self, mocked_qs): mocked_qs.side_effect = Exception() with self.assertRaises(TeamSubmissionInternalError): TeamSubmission.get_team_submission_by_uuid( self.default_submission.uuid)
def test_get_team_submission_by_uuid_nonexistant(self): fake_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee' with self.assertRaises(TeamSubmissionNotFoundError): TeamSubmission.get_team_submission_by_uuid(fake_uuid)
def test_get_team_submission_by_uuid(self): team_submission = TeamSubmission.get_team_submission_by_uuid( self.default_submission.uuid) self.assertEqual(team_submission.id, self.default_submission.id)