def test_create_submission_for_team_after_reassignment(self):
     """
     Call create_submission twice to simulate attempting a submission of a learner(s) that was reassigned to a
     different team.
     Expected outcome: No submissions created.
     """
     self._call_create_submission_for_team_with_default_args()
     # To simulate reassignment, call create_submission with a different team id.
     # no new submissions should be created as a result of this call. Therefore, the total number of submission
     # models is 4 (see self.student_ids).
     team_api.create_submission_for_team(
         COURSE_ID, ITEM_1_ID, TEAM_2_ID, self.user_1.id, [
             self.anonymous_user_id_map[self.user_1],
             '55555555555555555555555555555555',
             '66666666666666666666666666666666'
         ], ANSWER)
     ids = [
         sub.student_item.student_id
         for sub in Submission.objects.select_related('student_item').all()
     ]
     # We simulated reassignment by using a different team id in the call to create_submission. Therefore, 6
     # submissions should exist: 4 from the first call and 2 from the second call. We would not createa
     # submission for user_1 in the second call because she already has a submission from the first call.
     self.assertEqual(6, len(ids))
     # this assert checks that there is one and only one (no duplicate - which would indicate a double submission)
     # student id
     self.assertEqual(len(ids), len(set(ids)))
Esempio n. 2
0
 def test_create_submission_for_team_invalid_attempt(self):
     """
     Test for calling create_submission_for_team with an invalid attempt_number
     """
     with self.assertRaises(TeamSubmissionRequestError):
         team_api.create_submission_for_team(COURSE_ID,
                                             ITEM_1_ID,
                                             TEAM_1_ID,
                                             self.user_1.id,
                                             self.student_ids,
                                             ANSWER,
                                             attempt_number=-1)
Esempio n. 3
0
    def _create_test_submission_for_team(self):
        """
        Helper to create a team submission.
        Implicitly creates a TeamStaffWorkflow linked to the submission.

        Returns:
            TeamSubmission
        """
        # Create a team submission
        team_submission = team_submissions_api.create_submission_for_team(
            'mock-course',
            'mock-item',
            'mock-team-id',
            self.submitting_user_id,
            self.team_member_ids,
            '42'
        )

        # Create a team staff workflow linked to the team submission
        self._create_test_workflow(
            team_submission['team_submission_uuid'],
            course_id='mock-course',
            item_id='mock-item'
        )

        return team_submission
Esempio n. 4
0
 def _call_create_submission_for_team_with_default_args(self):
     """ Convenience method to call team_api.create_submission_for_team with some default arguments """
     return team_api.create_submission_for_team(
         COURSE_ID,
         ITEM_1_ID,
         TEAM_1_ID,
         self.user_1.id,
         self.student_ids,
         ANSWER
     )
    def create_team_submission(self, student_sub_data):
        """ A student submitting for a team should generate matching submissions for every member of the team. """
        if not self.has_team():
            msg = "Student {} has no team for course {}".format(
                self.get_student_item_dict()['student_id'],
                self.course_id
            )
            logger.exception(msg)
            raise NoTeamToCreateSubmissionForError(msg)

        # Import is placed here to avoid model import at project startup.
        from submissions import team_api

        team_info = self.get_team_info()
        # Store the student's response text in a JSON-encodable dict
        # so that later we can add additional response fields.
        student_sub_dict = prepare_submission_for_serialization(student_sub_data)

        self._collect_files_for_submission(student_sub_dict)

        self.check_for_empty_submission_and_raise_error(student_sub_dict)

        submitter_anonymous_user_id = self.xmodule_runtime.anonymous_student_id
        user = self.get_real_user(submitter_anonymous_user_id)
        student_item_dict = self.get_student_item_dict(anonymous_user_id=submitter_anonymous_user_id)
        anonymous_student_ids = self.get_anonymous_user_ids_for_team()
        submission = team_api.create_submission_for_team(
            self.course_id,
            student_item_dict['item_id'],
            team_info['team_id'],
            user.id,
            anonymous_student_ids,
            student_sub_dict,
        )

        self.create_team_workflow(submission["team_submission_uuid"])
        # Emit analytics event...
        self.runtime.publish(
            self,
            "openassessmentblock.create_team_submission",
            {
                "submission_uuid": submission["team_submission_uuid"],
                "team_id": team_info["team_id"],
                "attempt_number": submission["attempt_number"],
                "created_at": submission["created_at"],
                "submitted_at": submission["submitted_at"],
                "answer": submission["answer"],
            }
        )
        return submission
Esempio n. 6
0
 def _create_team_submission(self, course_id, item_id, team_id, submitting_user_id, team_member_student_ids):
     """
     Create a team submission and initialize a team workflow
     """
     team_submission = team_sub_api.create_submission_for_team(
         course_id,
         item_id,
         team_id,
         submitting_user_id,
         team_member_student_ids,
         ANSWER,
     )
     team_workflow_api.create_workflow(team_submission['team_submission_uuid'])
     return team_submission
Esempio n. 7
0
 def _create_submission(self):
     """
     Create a test team submission through the submissions api
     """
     self.users = [UserFactory.create() for _ in range(5)]
     self.team_submission_dict = sub_team_api.create_submission_for_team(
         self.course_id,
         self.item_id,
         'team-rocket',
         self.users[0].id,
         [user.id for user in self.users],
         'this-is-my-answer',
     )
     self.team_submission_uuid = self.team_submission_dict['team_submission_uuid']
     self.submission_uuids = self.team_submission_dict['submission_uuids']