def test_add_master_course_staff_to_ccx_with_exception(self): """ When exception raise from ``enroll_email`` assert that enrollment skipped for that staff or instructor. """ staff = self.make_staff() self.assertTrue(CourseStaffRole(self.course.id).has_user(staff)) # adding instructor to master course. instructor = self.make_instructor() self.assertTrue(CourseInstructorRole(self.course.id).has_user(instructor)) with mock.patch.object(CourseEnrollment, 'enroll_by_email', side_effect=CourseEnrollmentException()): add_master_course_staff_to_ccx(self.course, self.ccx_locator, self.ccx.display_name) self.assertFalse( CourseEnrollment.objects.filter(course_id=self.ccx_locator, user=staff).exists() ) self.assertFalse( CourseEnrollment.objects.filter(course_id=self.ccx_locator, user=instructor).exists() ) with mock.patch.object(CourseEnrollment, 'enroll_by_email', side_effect=SMTPException()): add_master_course_staff_to_ccx(self.course, self.ccx_locator, self.ccx.display_name) self.assertFalse( CourseEnrollment.objects.filter(course_id=self.ccx_locator, user=staff).exists() ) self.assertFalse( CourseEnrollment.objects.filter(course_id=self.ccx_locator, user=instructor).exists() )
def test_exception_on_enrollment_failure(self): program_enrollment = self._create_waiting_program_enrollment() self._create_waiting_course_enrollments(program_enrollment) with mock.patch('student.models.CourseEnrollment.enroll') as enrollMock: enrollMock.side_effect = CourseEnrollmentException('something has gone wrong') with pytest.raises(CourseEnrollmentException): UserSocialAuth.objects.create( user=self.user, uid='{0}:{1}'.format(self.provider_slug, self.external_id) )
def test_log_on_enrollment_failure(self): program_enrollment = self._create_waiting_program_enrollment() program_course_enrollments = self._create_waiting_course_enrollments( program_enrollment) with mock.patch( 'student.models.CourseEnrollment.enroll') as enrollMock: enrollMock.side_effect = CourseEnrollmentException( 'something has gone wrong') with LogCapture(logger.name) as log: with pytest.raises(CourseEnrollmentException): UserSocialAuth.objects.create(user=self.user, uid='{0}:{1}'.format( self.provider_slug, self.external_id)) error_template = u'Failed to enroll user={} with waiting program_course_enrollment={}: {}' log.check_present( (logger.name, 'WARNING', error_template.format(self.user.id, program_course_enrollments[0].id, 'something has gone wrong')))