Пример #1
0
    def test_flag_disabled(self):
        with self.store.bulk_operations(self.course_key):
            self._create_chapter(highlights=[u'highlights'])

        self.assertFalse(course_has_highlights(self.course_key))
        with self.assertRaises(CourseUpdateDoesNotExist):
            get_week_highlights(self.user, self.course_key, week_num=1)
    def test_flag_disabled(self):
        with self.store.bulk_operations(self.course_key):
            self._create_chapter(highlights=[u'highlights'])

        self.assertFalse(course_has_highlights(self.course_key))
        with self.assertRaises(CourseUpdateDoesNotExist):
            get_week_highlights(self.user, self.course_key, week_num=1)
 def test_flag_enabled(self):
     highlights = [u'highlights']
     with self.store.bulk_operations(self.course_key):
         self._create_chapter(highlights=highlights)
     self.assertTrue(course_has_highlights(self.course_key))
     self.assertEqual(
         get_week_highlights(self.user, self.course_key, week_num=1),
         highlights,
     )
Пример #4
0
 def test_flag_enabled(self):
     highlights = [u'highlights']
     with self.store.bulk_operations(self.course_key):
         self._create_chapter(highlights=highlights)
     self.assertTrue(course_has_highlights(self.course_key))
     self.assertEqual(
         get_week_highlights(self.user, self.course_key, week_num=1),
         highlights,
     )
Пример #5
0
    def test_staff_only(self):
        with self.store.bulk_operations(self.course_key):
            self._create_chapter(
                highlights=[u"I'm a secret!"],
                visible_to_staff_only=True,
            )

        self.assertTrue(course_has_highlights(self.course_key))
        with self.assertRaises(CourseUpdateDoesNotExist):
            get_week_highlights(self.user, self.course_key, week_num=1)
    def test_staff_only(self):
        with self.store.bulk_operations(self.course_key):
            self._create_chapter(
                highlights=[u"I'm a secret!"],
                visible_to_staff_only=True,
            )

        self.assertTrue(course_has_highlights(self.course_key))
        with self.assertRaises(CourseUpdateDoesNotExist):
            get_week_highlights(self.user, self.course_key, week_num=1)
Пример #7
0
def _get_experience_type(enrollment):
    """
    Returns the ScheduleExperience type for the given enrollment.

    Schedules will receive the Course Updates experience if the course has any section highlights defined.
    """
    if course_has_highlights(enrollment.course_id):
        return ScheduleExperience.EXPERIENCES.course_updates
    else:
        return ScheduleExperience.EXPERIENCES.default
Пример #8
0
def _get_experience_type(enrollment):
    """
    Returns the ScheduleExperience type for the given enrollment.

    Schedules will receive the Course Updates experience if the course has any section highlights defined.
    """
    if course_has_highlights(enrollment.course_id):
        return ScheduleExperience.EXPERIENCES.course_updates
    else:
        return ScheduleExperience.EXPERIENCES.default
Пример #9
0
def create_schedule(sender, **kwargs):
    if not kwargs['created']:
        # only create schedules when enrollment records are created
        return

    current_site = get_current_site()
    if current_site is None:
        log.debug('Schedules: No current site')
        return

    enrollment = kwargs['instance']
    schedule_config = ScheduleConfig.current(current_site)
    if (not schedule_config.create_schedules and
            not CREATE_SCHEDULE_WAFFLE_FLAG.is_enabled(enrollment.course_id)):
        log.debug(
            'Schedules: Creation not enabled for this course or for this site')
        return

    if not enrollment.course_overview.self_paced:
        log.debug('Schedules: Creation only enabled for self-paced courses')
        return

    # This represents the first date at which the learner can access the content. This will be the latter of
    # either the enrollment date or the course's start date.
    content_availability_date = max(enrollment.created,
                                    enrollment.course_overview.start)

    upgrade_deadline = _calculate_upgrade_deadline(enrollment.course_id,
                                                   content_availability_date)

    if course_has_highlights(enrollment.course_id):
        experience_type = ScheduleExperience.EXPERIENCES.course_updates
    else:
        experience_type = ScheduleExperience.EXPERIENCES.default

    if _should_randomly_suppress_schedule_creation(
            schedule_config,
            enrollment,
            upgrade_deadline,
            experience_type,
            content_availability_date,
    ):
        return

    schedule = Schedule.objects.create(enrollment=enrollment,
                                       start=content_availability_date,
                                       upgrade_deadline=upgrade_deadline)

    ScheduleExperience(schedule=schedule,
                       experience_type=experience_type).save()

    log.debug(
        'Schedules: created a new schedule starting at %s with an upgrade deadline of %s and experience type: %s',
        content_availability_date, upgrade_deadline,
        ScheduleExperience.EXPERIENCES[experience_type])
    def test_course_with_no_highlights(self):
        with self.store.bulk_operations(self.course_key):
            self._create_chapter(display_name=u"Week 1")
            self._create_chapter(display_name=u"Week 2")

        self.course = self.store.get_course(self.course_key)
        self.assertEqual(len(self.course.get_children()), 2)

        self.assertFalse(course_has_highlights(self.course_key))
        with self.assertRaises(CourseUpdateDoesNotExist):
            get_week_highlights(self.user, self.course_key, week_num=1)
Пример #11
0
    def test_course_with_no_highlights(self):
        with self.store.bulk_operations(self.course_key):
            self._create_chapter(display_name=u"Week 1")
            self._create_chapter(display_name=u"Week 2")

        self.course = self.store.get_course(self.course_key)  # lint-amnesty, pylint: disable=attribute-defined-outside-init
        self.assertEqual(len(self.course.get_children()), 2)

        self.assertFalse(course_has_highlights(self.course_key))
        with self.assertRaises(CourseUpdateDoesNotExist):
            get_week_highlights(self.user, self.course_key, week_num=1)
Пример #12
0
    def test_course_with_no_highlights(self):
        with self.store.bulk_operations(self.course_key):
            self._create_chapter(display_name=u"Week 1")
            self._create_chapter(display_name=u"Week 2")

        self.course = self.store.get_course(self.course_key)
        self.assertEqual(len(self.course.get_children()), 2)

        self.assertFalse(course_has_highlights(self.course_key))
        with self.assertRaises(CourseUpdateDoesNotExist):
            get_week_highlights(self.user, self.course_key, week_num=1)
Пример #13
0
def create_schedule(sender, **kwargs):
    if not kwargs['created']:
        # only create schedules when enrollment records are created
        return

    current_site = get_current_site()
    if current_site is None:
        log.debug('Schedules: No current site')
        return

    enrollment = kwargs['instance']
    schedule_config = ScheduleConfig.current(current_site)
    if not schedule_config.create_schedules:
        log.debug('Schedules: Creation not enabled for this course or for this site')
        return

    if not enrollment.course_overview.self_paced:
        log.debug('Schedules: Creation only enabled for self-paced courses')
        return

    # This represents the first date at which the learner can access the content. This will be the latter of
    # either the enrollment date or the course's start date.
    content_availability_date = max(enrollment.created, enrollment.course_overview.start)

    upgrade_deadline = _calculate_upgrade_deadline(enrollment.course_id, content_availability_date)

    if course_has_highlights(enrollment.course_id):
        experience_type = ScheduleExperience.EXPERIENCES.course_updates
    else:
        experience_type = ScheduleExperience.EXPERIENCES.default

    if _should_randomly_suppress_schedule_creation(
        schedule_config,
        enrollment,
        upgrade_deadline,
        experience_type,
        content_availability_date,
    ):
        return

    schedule = Schedule.objects.create(
        enrollment=enrollment,
        start=content_availability_date,
        upgrade_deadline=upgrade_deadline
    )

    ScheduleExperience(schedule=schedule, experience_type=experience_type).save()

    log.debug('Schedules: created a new schedule starting at %s with an upgrade deadline of %s and experience type: %s',
              content_availability_date, upgrade_deadline, ScheduleExperience.EXPERIENCES[experience_type])
Пример #14
0
    def test_highlights_disabled_for_messaging(self):
        highlights = [u'A test highlight.']
        with self.store.bulk_operations(self.course_key):
            self._create_chapter(highlights=highlights)
            self.course.highlights_enabled_for_messaging = False
            self.store.update_item(self.course, self.user.id)

        self.assertFalse(course_has_highlights(self.course_key))

        with self.assertRaises(CourseUpdateDoesNotExist):
            get_week_highlights(
                self.user,
                self.course_key,
                week_num=1,
            )
    def test_highlights_disabled_for_messaging(self):
        highlights = [u'A test highlight.']
        with self.store.bulk_operations(self.course_key):
            self._create_chapter(highlights=highlights)
            self.course.highlights_enabled_for_messaging = False
            self.store.update_item(self.course, self.user.id)

        self.assertFalse(course_has_highlights(self.course_key))

        with self.assertRaises(CourseUpdateDoesNotExist):
            get_week_highlights(
                self.user,
                self.course_key,
                week_num=1,
            )
    def test_course_with_highlights(self):
        with self.store.bulk_operations(self.course_key):
            self._create_chapter(highlights=[u'a', u'b', u'á'])
            self._create_chapter(highlights=[])
            self._create_chapter(highlights=[u'skipped a week'])

        self.assertTrue(course_has_highlights(self.course_key))

        self.assertEqual(
            get_week_highlights(self.user, self.course_key, week_num=1),
            [u'a', u'b', u'á'],
        )
        self.assertEqual(
            get_week_highlights(self.user, self.course_key, week_num=2),
            [u'skipped a week'],
        )
        with self.assertRaises(CourseUpdateDoesNotExist):
            get_week_highlights(self.user, self.course_key, week_num=3)
Пример #17
0
    def test_course_with_highlights(self):
        with self.store.bulk_operations(self.course_key):
            self._create_chapter(highlights=[u'a', u'b', u'á'])
            self._create_chapter(highlights=[])
            self._create_chapter(highlights=[u'skipped a week'])

        self.assertTrue(course_has_highlights(self.course_key))

        self.assertEqual(
            get_week_highlights(self.user, self.course_key, week_num=1),
            [u'a', u'b', u'á'],
        )
        self.assertEqual(
            get_week_highlights(self.user, self.course_key, week_num=2),
            [u'skipped a week'],
        )
        with self.assertRaises(CourseUpdateDoesNotExist):
            get_week_highlights(self.user, self.course_key, week_num=3)
Пример #18
0
 def _get_course_has_highlights(cls, course):
     # Avoid circular import here
     from openedx.core.djangoapps.schedules.content_highlights import course_has_highlights
     return course_has_highlights(course)