def test_enroll_inactive_user_again(self, auto_enroll): course_key = CourseLocator('Robot', 'fAKE', 'C--se--ID') before_ideal = SettableEnrollmentState( user=True, enrollment=False, allowed=True, auto_enroll=auto_enroll, ) print("checking initialization...") user = UserFactory() user.is_active = False user.save() eobjs = EnrollmentObjects( user.email, None, None, CourseEnrollmentAllowed.objects.create(email=user.email, course_id=course_key, auto_enroll=auto_enroll)) before = EmailEnrollmentState(course_key, eobjs.email) self.assertEqual(before, before_ideal) print('running action...') enroll_email(self.course_key, eobjs.email, auto_enroll=auto_enroll) print('checking effects...') after_ideal = SettableEnrollmentState( user=True, enrollment=False, allowed=True, auto_enroll=auto_enroll, ) after = EmailEnrollmentState(self.course_key, eobjs.email) self.assertEqual(after, after_ideal)
def test_enroll_inactive_user(self, auto_enroll): before_ideal = SettableEnrollmentState( user=True, enrollment=False, allowed=False, auto_enroll=False, ) print("checking initialization...") eobjs = before_ideal.create_user(self.course_key, is_active=False) before = EmailEnrollmentState(self.course_key, eobjs.email) self.assertEqual(before, before_ideal) print('running action...') enroll_email(self.course_key, eobjs.email, auto_enroll=auto_enroll) print('checking effects...') after_ideal = SettableEnrollmentState( user=True, enrollment=False, allowed=True, auto_enroll=auto_enroll, ) after = EmailEnrollmentState(self.course_key, eobjs.email) self.assertEqual(after, after_ideal)
def test_mes_create(self): """ Test SettableEnrollmentState creation of user. """ mes = SettableEnrollmentState(user=True, enrollment=True, allowed=False, auto_enroll=False) # enrollment objects eobjs = mes.create_user(self.course_key) ees = EmailEnrollmentState(self.course_key, eobjs.email) self.assertEqual(mes, ees)
def _run_state_change_test(self, before_ideal, after_ideal, action): """ Runs a state change test. `before_ideal` and `after_ideal` are SettableEnrollmentState's `action` is a function which will be run in the middle. `action` should transition the world from before_ideal to after_ideal `action` will be supplied the following arguments (None-able arguments) `email` is an email string """ # initialize & check before print "checking initialization..." eobjs = before_ideal.create_user(self.course_key) before = EmailEnrollmentState(self.course_key, eobjs.email) self.assertEqual(before, before_ideal) # do action print "running action..." action(eobjs.email) # check after print "checking effects..." after = EmailEnrollmentState(self.course_key, eobjs.email) self.assertEqual(after, after_ideal)