def test_date_with_self_paced_with_enrollment_after_course_start(self):
        """ Enrolling after a course begins should result in the upgrade deadline being set relative to the
        enrollment date.

        Additionally, OrgDynamicUpgradeDeadlineConfiguration should override the number of days until the deadline,
        and CourseDynamicUpgradeDeadlineConfiguration should override the org-level override.
        """
        global_config = DynamicUpgradeDeadlineConfiguration.objects.create(enabled=True)
        course = create_self_paced_course_run(days_till_start=-1, org_id='TestOrg')
        enrollment = CourseEnrollmentFactory(course_id=course.id, mode=CourseMode.AUDIT)
        block = VerifiedUpgradeDeadlineDate(course, enrollment.user)
        expected = enrollment.created + timedelta(days=global_config.deadline_days)
        assert block.date == expected

        # Orgs should be able to override the deadline
        org_config = OrgDynamicUpgradeDeadlineConfiguration.objects.create(
            enabled=True, org_id=course.org, deadline_days=4
        )
        enrollment = CourseEnrollmentFactory(course_id=course.id, mode=CourseMode.AUDIT)
        block = VerifiedUpgradeDeadlineDate(course, enrollment.user)
        expected = enrollment.created + timedelta(days=org_config.deadline_days)
        assert block.date == expected

        # Courses should be able to override the deadline (and the org-level override)
        course_config = CourseDynamicUpgradeDeadlineConfiguration.objects.create(
            enabled=True, course_id=course.id, deadline_days=3
        )
        enrollment = CourseEnrollmentFactory(course_id=course.id, mode=CourseMode.AUDIT)
        block = VerifiedUpgradeDeadlineDate(course, enrollment.user)
        expected = enrollment.created + timedelta(days=course_config.deadline_days)
        assert block.date == expected
Beispiel #2
0
    def test_date_with_existing_schedule(self):
        """ If a schedule is created while deadlines are disabled, they shouldn't magically appear once the feature is
        turned on. """
        course = create_self_paced_course_run(days_till_start=-1)
        DynamicUpgradeDeadlineConfiguration.objects.create(enabled=False)
        course_config = CourseDynamicUpgradeDeadlineConfiguration.objects.create(
            enabled=False, course_id=course.id)
        enrollment = CourseEnrollmentFactory(course_id=course.id,
                                             mode=CourseMode.AUDIT)

        # The enrollment has a schedule, but the upgrade deadline should be None
        self.assertIsNone(enrollment.schedule.upgrade_deadline)

        block = VerifiedUpgradeDeadlineDate(course, enrollment.user)
        expected = CourseMode.objects.get(
            course_id=course.id,
            mode_slug=CourseMode.VERIFIED).expiration_datetime
        self.assertEqual(block.date, expected)

        # Now if we turn on the feature for this course, this existing enrollment should be unaffected
        course_config.enabled = True
        course_config.save()

        block = VerifiedUpgradeDeadlineDate(course, enrollment.user)
        self.assertEqual(block.date, expected)
 def test_date_with_self_paced_without_dynamic_upgrade_deadline(self):
     """ Disabling the dynamic upgrade deadline functionality should result in the verified mode's
     expiration date being returned. """
     DynamicUpgradeDeadlineConfiguration.objects.create(enabled=False)
     course = create_self_paced_course_run()
     expected = CourseMode.objects.get(course_id=course.id, mode_slug=CourseMode.VERIFIED).expiration_datetime
     enrollment = CourseEnrollmentFactory(course_id=course.id, mode=CourseMode.AUDIT)
     block = VerifiedUpgradeDeadlineDate(course, enrollment.user)
     assert block.date == expected
 def test_date_with_self_paced_with_enrollment_before_course_start(self):
     """ Enrolling before a course begins should result in the upgrade deadline being set relative to the
     course start date. """
     global_config = DynamicUpgradeDeadlineConfiguration.objects.create(enabled=True)
     course = create_self_paced_course_run(days_till_start=3)
     overview = CourseOverview.get_from_id(course.id)
     expected = overview.start + timedelta(days=global_config.deadline_days)
     enrollment = CourseEnrollmentFactory(course_id=course.id, mode=CourseMode.AUDIT)
     block = VerifiedUpgradeDeadlineDate(course, enrollment.user)
     assert block.date == expected
     self._check_text(block)
    def test_ecommerce_checkout_redirect(self):
        """Verify the block link redirects to ecommerce checkout if it's enabled."""
        sku = 'TESTSKU'
        configuration = CommerceConfiguration.objects.create(checkout_on_ecommerce_service=True)
        course = create_course_run()
        user = create_user()
        course_mode = CourseMode.objects.get(course_id=course.id, mode_slug=CourseMode.VERIFIED)
        course_mode.sku = sku
        course_mode.save()
        CourseEnrollmentFactory(course_id=course.id, user=user, mode=CourseMode.VERIFIED)

        block = VerifiedUpgradeDeadlineDate(course, user)
        assert block.link == f'{configuration.basket_checkout_page}?sku={sku}'
 def test_verified_upgrade_deadline_alert(self, current_time, expected_message_html):
     """
     Verify the verified upgrade deadline alerts.
     """
     with freeze_time(current_time):
         block = VerifiedUpgradeDeadlineDate(self.course, self.request.user)
         block.register_alerts(self.request, self.course)
         messages = list(CourseHomeMessages.user_messages(self.request))
         if expected_message_html:
             self.assertEqual(len(messages), 1)
             self.assertIn(expected_message_html, messages[0].message_html)
         else:
             self.assertEqual(len(messages), 0)