def test_get_teammates_with_submissions_from_other_teams__cancelled(self): # Make a team submission with default users, under TEAM_1 team_submission = self._make_team_submission( attempt_number=1, course_id=COURSE_ID, item_id=ITEM_1_ID, team_id=TEAM_1_ID, status=None, create_submissions=True ) # Simulate resetting student state for the team, which causes the submissions to be deleted team_api.reset_scores(team_submission.uuid, clear_state=True) team_submission.refresh_from_db() self.assertEqual(team_submission.status, DELETED) for individual_submission in team_submission.submissions.all(): self.assertEqual(individual_submission.status, DELETED) # Now, everyone has moved to a new team, but their old submission was deleted, so no one should be listed with self.assertNumQueries(1): external_submissions = team_api.get_teammates_with_submissions_from_other_teams( COURSE_ID, ITEM_1_ID, TEAM_2_ID, self.student_ids ) # Returns no one, since the submission was cancelled self.assertEqual(external_submissions, [])
def test_get_teammates_with_submissions_from_other_teams(self): # Make a team submission with default users, under TEAM_1 self._make_team_submission( attempt_number=1, course_id=COURSE_ID, item_id=ITEM_1_ID, team_id=TEAM_1_ID, status=None, create_submissions=True ) # Check against TEAM_2 with 2 additional user IDs added (that don't have a submission) team_ids = [ self.anonymous_user_id_map[student] for student in [ self.user_1, self.user_2, self.user_3, self.user_4 ] ] + ['55555555555555', '666666666666666666'] with self.assertNumQueries(1): external_submissions = team_api.get_teammates_with_submissions_from_other_teams( COURSE_ID, ITEM_1_ID, TEAM_2_ID, team_ids ) # Should get 1 entry for each of the default users self.assertEqual(len(external_submissions), 4) for student_id in self.student_ids: self.assertIn( { 'student_id': student_id, 'team_id': TEAM_1_ID }, external_submissions )
def get_team_submission_context(self, context): """ Populate the passed context object with team info, including a set of students on the team with submissions to the current item from another team, under the key `team_members_with_external_submissions`. Args: context (dict): render context to add team submission context into Returns (dict): context arg with additional team-related fields """ from submissions import team_api try: team_info = self.get_team_info() if team_info: context.update(team_info) if self.is_course_staff: return student_item_dict = self.get_student_item_dict() external_submissions = team_api.get_teammates_with_submissions_from_other_teams( self.course_id, student_item_dict["item_id"], team_info["team_id"], self.get_anonymous_user_ids_for_team()) context[ "team_members_with_external_submissions"] = list_to_conversational_format( [ self.get_username(submission['student_id']) for submission in external_submissions ]) except ObjectDoesNotExist: error_msg = '{}: User associated with anonymous_user_id {} can not be found.' logger.error( error_msg.format( str(self.location), self.get_student_item_dict()['student_id'], )) except NoSuchServiceError: logger.error('{}: Teams service is unavailable'.format( str(self.location)))