def test_exam_authorization_attempts_consumed(self): """ test exam_authorization when user passed and paid, but used all their attempts """ create_order(self.user, self.course_run) mmtrack = get_mmtrack(self.user, self.program) self.assertTrue(mmtrack.has_paid(self.course_run.edx_course_key)) self.assertTrue( mmtrack.has_passed_course(self.course_run.edx_course_key)) old_run = ExamRunFactory.create(course=self.course_run.course) ExamAuthorizationFactory.create_batch( ATTEMPTS_PER_PAID_RUN, exam_run=old_run, user=mmtrack.user, course=self.course_run.course, exam_taken=True, ) assert ExamAuthorization.objects.filter( user=mmtrack.user, course=self.course_run.course).count() == 2 with self.assertRaises(ExamAuthorizationException): authorize_for_exam_run(self.user, self.course_run, self.exam_run) # assert no new authorizations got created assert ExamAuthorization.objects.filter( user=mmtrack.user, course=self.course_run.course).count() == 2
def test_exam_authorization_attempts_consumed(self): """ test exam_authorization when user passed and paid, but used all their attempts """ create_order(self.user, self.course_run) mmtrack = get_mmtrack(self.user, self.program) self.assertTrue(mmtrack.has_paid(self.course_run.edx_course_key)) self.assertTrue(mmtrack.has_passed_course(self.course_run.edx_course_key)) old_run = ExamRunFactory.create(course=self.course_run.course) ExamAuthorizationFactory.create_batch( ATTEMPTS_PER_PAID_RUN, exam_run=old_run, user=mmtrack.user, course=self.course_run.course, exam_taken=True, ) assert ExamAuthorization.objects.filter( user=mmtrack.user, course=self.course_run.course ).count() == 2 with self.assertRaises(ExamAuthorizationException): authorize_for_exam_run(mmtrack, self.course_run, self.exam_run) # assert no new authorizations got created assert ExamAuthorization.objects.filter( user=mmtrack.user, course=self.course_run.course ).count() == 2
def test_process_result_exam(self): """Test that the authorization is marked as taken and a ProctoredExamGrade created""" exam_results = [] auths = [] # create a bunch of results that are passes for auth in ExamAuthorizationFactory.create_batch(5, course=self.course): exam_results.append( EXAMResultFactory.create( passed=True, client_candidate_id=auth.user.profile.student_id, client_authorization_id=auth.id, )) auths.append(auth) # create a bunch of results that are failed for auth in ExamAuthorizationFactory.create_batch(5, course=self.course): exam_results.append( EXAMResultFactory.create( failed=True, client_candidate_id=auth.user.profile.student_id, client_authorization_id=auth.id, )) auths.append(auth) grades = ProctoredExamGrade.objects.filter(course=self.course) assert grades.count() == 0 with patch('exams.pearson.download.EXAMReader.read', return_value=(exam_results, [])): assert self.processor.process_exam_file("/tmp/file.ext") == (True, []) for auth in auths: auth.refresh_from_db() assert auth.exam_no_show is False assert auth.exam_taken is True sorted_exam_results = sorted( exam_results, key=lambda result: result.client_authorization_id) sorted_grades = list(grades.order_by('client_authorization_id')) assert len(sorted_grades) == len(sorted_exam_results) for grade, exam_result in zip(sorted_grades, sorted_exam_results): assert grade.exam_date == exam_result.exam_date assert grade.passing_score == exam_result.passing_score assert grade.grade == exam_result.grade assert grade.score == exam_result.score assert grade.passed is (exam_result.grade == EXAM_GRADE_PASS) assert grade.percentage_grade == float(exam_result.score / 100.0) expected_data = dict( exam_result._asdict()) # _asdict() returns an OrderedDict expected_data['exam_date'] = expected_data['exam_date'].isoformat() assert grade.row_data == expected_data
def test_process_result_exam(self): """Test that the authorization is marked as taken and a ProctoredExamGrade created""" exam_results = [] auths = [] # create a bunch of results that are passes for auth in ExamAuthorizationFactory.create_batch(5, course=self.course): exam_results.append(EXAMResultFactory.create( passed=True, client_candidate_id=auth.user.profile.student_id, client_authorization_id=auth.id, )) auths.append(auth) # create a bunch of results that are failed for auth in ExamAuthorizationFactory.create_batch(5, course=self.course): exam_results.append(EXAMResultFactory.create( failed=True, client_candidate_id=auth.user.profile.student_id, client_authorization_id=auth.id, )) auths.append(auth) grades = ProctoredExamGrade.objects.filter(course=self.course) assert grades.count() == 0 with patch('exams.pearson.download.EXAMReader.read', return_value=(exam_results, [])): assert self.processor.process_exam_file("/tmp/file.ext") == (True, []) for auth in auths: auth.refresh_from_db() assert auth.exam_no_show is False assert auth.exam_taken is True sorted_exam_results = sorted(exam_results, key=lambda result: result.client_authorization_id) sorted_grades = list(grades.order_by('client_authorization_id')) assert len(sorted_grades) == len(sorted_exam_results) for grade, exam_result in zip(sorted_grades, sorted_exam_results): assert grade.exam_date == exam_result.exam_date assert grade.passing_score == exam_result.passing_score assert grade.grade == exam_result.grade assert grade.score == exam_result.score assert grade.passed is (exam_result.grade == EXAM_GRADE_PASS) assert grade.percentage_grade == float(exam_result.score / 100.0) expected_data = dict(exam_result._asdict()) # _asdict() returns an OrderedDict expected_data['exam_date'] = expected_data['exam_date'].isoformat() assert grade.row_data == expected_data
def setUpTestData(cls): sftp = Mock() cls.processor = download.ArchivedResponseProcessor(sftp) cls.course = course = CourseFactory.create() cls.success_auths = ExamAuthorizationFactory.create_batch( 2, course=course) cls.failure_auths = ExamAuthorizationFactory.create_batch( 2, course=course) cls.success_results = ([ EACResult( client_authorization_id=auth.id, client_candidate_id=auth.user.profile.student_id, date=FIXED_DATETIME, status=EAC_SUCCESS_STATUS, message='', ) for auth in cls.success_auths ], []) cls.failed_results = ([ EACResult( client_authorization_id=cls.failure_auths[0].id, client_candidate_id=cls.failure_auths[0].user.profile. student_id, date=FIXED_DATETIME, status=EAC_FAILURE_STATUS, message='', ), EACResult( client_authorization_id=cls.failure_auths[1].id, client_candidate_id=cls.failure_auths[1].user.profile. student_id, date=FIXED_DATETIME, status=EAC_FAILURE_STATUS, message='wrong username', ), ], []) cls.all_results = ( cls.success_results[0] + cls.failed_results[0], cls.success_results[1] + cls.failed_results[1], )
def setUpTestData(cls): sftp = Mock() cls.processor = download.ArchivedResponseProcessor(sftp) cls.course = course = CourseFactory.create() cls.success_auths = ExamAuthorizationFactory.create_batch(2, course=course) cls.failure_auths = ExamAuthorizationFactory.create_batch(2, course=course) cls.success_results = ([ EACResult( client_authorization_id=auth.id, client_candidate_id=auth.user.profile.student_id, date=FIXED_DATETIME, status=EAC_SUCCESS_STATUS, message='', ) for auth in cls.success_auths ], []) cls.failed_results = ([ EACResult( client_authorization_id=cls.failure_auths[0].id, client_candidate_id=cls.failure_auths[0].user.profile.student_id, date=FIXED_DATETIME, status=EAC_FAILURE_STATUS, message='', ), EACResult( client_authorization_id=cls.failure_auths[1].id, client_candidate_id=cls.failure_auths[1].user.profile.student_id, date=FIXED_DATETIME, status=EAC_FAILURE_STATUS, message='wrong username', ), ], []) cls.all_results = ( cls.success_results[0] + cls.failed_results[0], cls.success_results[1] + cls.failed_results[1], )
def setUpTestData(cls): with mute_signals(post_save): cls.exam_auths = ExamAuthorizationFactory.create_batch( 10, status=ExamAuthorization.STATUS_PENDING)
def setUpTestData(cls): with mute_signals(post_save): cls.exam_auths = ExamAuthorizationFactory.create_batch(10, status=ExamAuthorization.STATUS_PENDING)