def _set_up_invited_student(self, course, active=False, enrolled=True, course_mode=''): """ Helper function to create a user in the right state, invite them into the course, and update their course mode if needed. """ email = '*****@*****.**' user = UserFactory(username='******', first_name='Student', last_name='Person', email=email, is_active=active) # invite the user to the course cea = CourseEnrollmentAllowed(email=email, course_id=course.id, auto_enroll=True) cea.save() if enrolled: CourseEnrollment.enroll(user, course.id) if course_mode: course_enrollment = CourseEnrollment.objects.get( user=user, course_id=self.course.id) course_enrollment.mode = course_mode course_enrollment.save() return user
def test_unenroll_non_user_student( self, view_name, send_email, outbox_count, student_form_input_name, button_tuple, identifier): """ Unenroll a list of students who are not users yet """ self.make_coach() course = CourseFactory.create() ccx = self.make_ccx() course_key = CCXLocator.from_course_locator(course.id, ccx.id) outbox = self.get_outbox() CourseEnrollmentAllowed(course_id=course_key, email=identifier) assert outbox == [] url = reverse( view_name, kwargs={'course_id': course_key} ) data = { button_tuple[0]: button_tuple[1], student_form_input_name: ','.join([identifier, ]), } if send_email: data['email-students'] = 'Notify-students-by-email' response = self.client.post(url, data=data, follow=True) assert response.status_code == 200 # we were redirected to our current location assert len(response.redirect_chain) == 1 assert 302 in response.redirect_chain[0] assert len(outbox) == outbox_count assert not CourseEnrollmentAllowed.objects.filter(course_id=course_key, email=identifier).exists()