def test_auto_enroll_step(self, course_modes, enrollment_mode, email_opt_in, email_opt_in_result): # Create the course modes for the test case for mode_slug in course_modes: CourseModeFactory.create( course_id=self.course.id, mode_slug=mode_slug, mode_display_name=mode_slug.capitalize() ) # Simulate the pipeline step, passing in a course ID # to indicate that the user was trying to enroll # when they started the auth process. strategy = self._fake_strategy() strategy.session_set('enroll_course_id', unicode(self.course.id)) strategy.session_set('email_opt_in', email_opt_in) result = pipeline.change_enrollment(strategy, 1, user=self.user) # pylint: disable=assignment-from-no-return,redundant-keyword-arg self.assertEqual(result, {}) # Check that the user was or was not enrolled # (this will vary based on the course mode) if enrollment_mode is not None: actual_mode, is_active = CourseEnrollment.enrollment_mode_for_user(self.user, self.course.id) self.assertTrue(is_active) self.assertEqual(actual_mode, enrollment_mode) else: self.assertFalse(CourseEnrollment.is_enrolled(self.user, self.course.id)) # Check that the Email Opt In option was set tag = UserOrgTag.objects.get(user=self.user) self.assertIsNotNone(tag) self.assertEquals(tag.value, email_opt_in_result)
def test_auto_enroll_step(self, course_modes, enrollment_mode, email_opt_in, email_opt_in_result): # Create the course modes for the test case for mode_slug in course_modes: CourseModeFactory.create(course_id=self.course.id, mode_slug=mode_slug, mode_display_name=mode_slug.capitalize()) # Simulate the pipeline step, passing in a course ID # to indicate that the user was trying to enroll # when they started the auth process. strategy = self._fake_strategy() strategy.session_set('enroll_course_id', unicode(self.course.id)) strategy.session_set('email_opt_in', email_opt_in) result = pipeline.change_enrollment(strategy, 1, user=self.user) # pylint: disable=assignment-from-no-return,redundant-keyword-arg self.assertEqual(result, {}) # Check that the user was or was not enrolled # (this will vary based on the course mode) if enrollment_mode is not None: actual_mode, is_active = CourseEnrollment.enrollment_mode_for_user( self.user, self.course.id) self.assertTrue(is_active) self.assertEqual(actual_mode, enrollment_mode) else: self.assertFalse( CourseEnrollment.is_enrolled(self.user, self.course.id)) # Check that the Email Opt In option was set tag = UserOrgTag.objects.get(user=self.user) self.assertIsNotNone(tag) self.assertEquals(tag.value, email_opt_in_result)
def test_auto_enroll_step(self, course_modes, enrollment_mode): # Create the course modes for the test case for mode_slug in course_modes: CourseModeFactory.create(course_id=self.course.id, mode_slug=mode_slug, mode_display_name=mode_slug.capitalize()) # Simulate the pipeline step, passing in a course ID # to indicate that the user was trying to enroll # when they started the auth process. strategy = self._fake_strategy() strategy.session_set('enroll_course_id', unicode(self.course.id)) result = pipeline.change_enrollment(strategy, 1, user=self.user) # pylint: disable=E1111,E1124 self.assertEqual(result, {}) # Check that the user was or was not enrolled # (this will vary based on the course mode) if enrollment_mode is not None: actual_mode, is_active = CourseEnrollment.enrollment_mode_for_user( self.user, self.course.id) self.assertTrue(is_active) self.assertEqual(actual_mode, enrollment_mode) else: self.assertFalse( CourseEnrollment.is_enrolled(self.user, self.course.id))
def test_auto_enroll_step(self, course_modes, enrollment_mode): # Create the course modes for the test case for mode_slug in course_modes: CourseModeFactory.create( course_id=self.course.id, mode_slug=mode_slug, mode_display_name=mode_slug.capitalize() ) # Simulate the pipeline step, passing in a course ID # to indicate that the user was trying to enroll # when they started the auth process. strategy = self._fake_strategy() strategy.session_set('enroll_course_id', unicode(self.course.id)) result = pipeline.change_enrollment(strategy, 1, user=self.user) # pylint: disable=E1111,E1124 self.assertEqual(result, {}) # Check that the user was or was not enrolled # (this will vary based on the course mode) if enrollment_mode is not None: actual_mode, is_active = CourseEnrollment.enrollment_mode_for_user(self.user, self.course.id) self.assertTrue(is_active) self.assertEqual(actual_mode, enrollment_mode) else: self.assertFalse(CourseEnrollment.is_enrolled(self.user, self.course.id))
def test_blocked_by_embargo(self): strategy = self._fake_strategy() strategy.session_set('enroll_course_id', unicode(self.course.id)) with restrict_course(self.course.id): result = pipeline.change_enrollment(strategy, 1, user=self.user) # pylint: disable=assignment-from-no-return,redundant-keyword-arg # Verify that we were NOT enrolled self.assertEqual(result, {}) self.assertFalse(CourseEnrollment.is_enrolled(self.user, self.course.id))
def test_skip_enroll_from_dashboard(self): strategy = self._fake_strategy() strategy.session_set('enroll_course_id', unicode(self.course.id)) # Simulate completing the pipeline from the student dashboard's # "link account" button. result = pipeline.change_enrollment(strategy, 1, user=self.user, is_dashboard=True) # pylint: disable=assignment-from-no-return,redundant-keyword-arg # Verify that we were NOT enrolled self.assertEqual(result, {}) self.assertFalse(CourseEnrollment.is_enrolled(self.user, self.course.id))
def test_skip_enroll_from_dashboard(self): strategy = self._fake_strategy() strategy.session_set('enroll_course_id', unicode(self.course.id)) # Simulate completing the pipeline from the student dashboard's # "link account" button. result = pipeline.change_enrollment(strategy, 1, user=self.user, auth_entry=pipeline.AUTH_ENTRY_DASHBOARD) # pylint: disable=assignment-from-no-return,redundant-keyword-arg # Verify that we were NOT enrolled self.assertEqual(result, {}) self.assertFalse(CourseEnrollment.is_enrolled(self.user, self.course.id))
def test_auto_enroll_not_accessible(self): # Set the course open date in the future tomorrow = datetime.datetime.now(pytz.utc) + datetime.timedelta(days=1) self.course.enrollment_start = tomorrow self.update_course(self.course, self.user.id) # Finish authentication and try to auto-enroll # This should fail silently, with no exception strategy = self._fake_strategy() strategy.session_set('enroll_course_id', unicode(self.course.id)) result = pipeline.change_enrollment(strategy, 1, user=self.user) # pylint: disable=assignment-from-no-return,redundant-keyword-arg self.assertEqual(result, {}) # Verify that we were NOT enrolled self.assertFalse(CourseEnrollment.is_enrolled(self.user, self.course.id))
def test_add_white_label_to_cart(self): # Create a white label course (honor with a minimum price) CourseModeFactory.create(course_id=self.course.id, mode_slug="honor", mode_display_name="Honor", min_price=100) # Simulate the pipeline step for enrolling in this course strategy = self._fake_strategy() strategy.session_set('enroll_course_id', unicode(self.course.id)) result = pipeline.change_enrollment(strategy, 1, user=self.user) # pylint: disable=assignment-from-no-return,redundant-keyword-arg self.assertEqual(result, {}) # Expect that the uesr is NOT enrolled in the course # because the user has not yet paid self.assertFalse( CourseEnrollment.is_enrolled(self.user, self.course.id)) # Expect that the course was added to the shopping cart cart = Order.get_cart_for_user(self.user) self.assertTrue(cart.has_items(PaidCourseRegistration)) order_item = PaidCourseRegistration.objects.get(order=cart) self.assertEqual(order_item.course_id, self.course.id)
def test_add_white_label_to_cart(self): # Create a white label course (honor with a minimum price) CourseModeFactory.create( course_id=self.course.id, mode_slug="honor", mode_display_name="Honor", min_price=100 ) # Simulate the pipeline step for enrolling in this course strategy = self._fake_strategy() strategy.session_set('enroll_course_id', unicode(self.course.id)) result = pipeline.change_enrollment(strategy, 1, user=self.user) # pylint: disable=assignment-from-no-return,redundant-keyword-arg self.assertEqual(result, {}) # Expect that the uesr is NOT enrolled in the course # because the user has not yet paid self.assertFalse(CourseEnrollment.is_enrolled(self.user, self.course.id)) # Expect that the course was added to the shopping cart cart = Order.get_cart_for_user(self.user) self.assertTrue(cart.has_items(PaidCourseRegistration)) order_item = PaidCourseRegistration.objects.get(order=cart) self.assertEqual(order_item.course_id, self.course.id)
def test_no_course_id_skips_enroll(self): strategy = self._fake_strategy() result = pipeline.change_enrollment(strategy, 1, user=self.user) # pylint: disable=assignment-from-no-return,redundant-keyword-arg self.assertEqual(result, {}) self.assertFalse( CourseEnrollment.is_enrolled(self.user, self.course.id))
def test_no_course_id_skips_enroll(self): strategy = self._fake_strategy() result = pipeline.change_enrollment(strategy, 1, user=self.user) # pylint: disable=assignment-from-no-return,redundant-keyword-arg self.assertEqual(result, {}) self.assertFalse(CourseEnrollment.is_enrolled(self.user, self.course.id))
def test_no_course_id_skips_enroll(self): strategy = self._fake_strategy() result = pipeline.change_enrollment(strategy, 1, user=self.user) # pylint: disable=E1111,E1124 self.assertEqual(result, {}) self.assertFalse( CourseEnrollment.is_enrolled(self.user, self.course.id))
def test_no_course_id_skips_enroll(self): strategy = self._fake_strategy() result = pipeline.change_enrollment(strategy, 1, user=self.user) # pylint: disable=E1111,E1124 self.assertEqual(result, {}) self.assertFalse(CourseEnrollment.is_enrolled(self.user, self.course.id))