示例#1
0
    def test_exam_authorization_multiple_runs(self):
        """Test that if the first enrollment is invalid it checks the second, but not the third"""
        exam_run = ExamRunFactory.create(course=self.course)
        mmtrack = get_mmtrack(self.user, self.program)

        with patch('exams.api.authorize_for_exam_run') as mock:
            mock.side_effect = [ExamAuthorizationException('invalid'), None, None]
            authorize_for_latest_passed_course(mmtrack, exam_run)

        assert mock.call_count == 2
        for enrollment in self.final_grades[:2]:  # two most recent runs
            mock.assert_any_call(mmtrack, enrollment.course_run, exam_run)
示例#2
0
def authorize_enrollment_for_exam_run(enrollment_ids, exam_run_id):
    """
    Task to authorize all eligible enrollments in the list for the given exam run

    Args:
        enrollment_ids (list): a list of program enrollment ids
        exam_run_id (int): an exam run id to authorize for

    Returns:
        None
    """
    exam_run = ExamRun.objects.get(id=exam_run_id)
    for enrollment in ProgramEnrollment.objects.filter(
            id__in=enrollment_ids).prefetch_related('user'):
        try:
            authorize_for_latest_passed_course(enrollment.user, exam_run)
        # pylint: disable=bare-except
        except:
            log.exception('Impossible to authorize user "%s" for exam_run %s',
                          enrollment.user.username, exam_run.id)