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_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_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)
    def test_highlights_disabled_for_messaging(self):
        highlights = ['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)

        assert not course_has_highlights_from_store(self.course_key)

        with pytest.raises(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,
            )
Exemplo n.º 6
0
    def schedules_for_bin(self):
        week_num = abs(self.day_offset) / 7
        schedules = self.get_schedules_with_target_date_by_bin_and_orgs(
            order_by='enrollment__course',
        )

        template_context = get_base_template_context(self.site)
        for schedule in schedules:
            enrollment = schedule.enrollment
            user = enrollment.user

            try:
                week_highlights = get_week_highlights(user, enrollment.course_id, week_num)
            except CourseUpdateDoesNotExist:
                LOG.warning(
                    'Weekly highlights for user {} in week {} of course {} does not exist or is disabled'.format(
                        user, week_num, enrollment.course_id
                    )
                )
                # continue to the next schedule, don't yield an email for this one
            else:
                template_context.update({
                    'course_name': schedule.enrollment.course.display_name,
                    'course_url': _get_trackable_course_home_url(enrollment.course_id),

                    'week_num': week_num,
                    'week_highlights': week_highlights,

                    # This is used by the bulk email optout policy
                    'course_ids': [str(enrollment.course_id)],
                })
                template_context.update(_get_upsell_information_for_schedule(user, schedule))

                yield (user, schedule.enrollment.course.closest_released_language, template_context)
 def test_happy_path(self):
     highlights = ['highlights']
     with self.store.bulk_operations(self.course_key):
         self._create_chapter(highlights=highlights)
     assert course_has_highlights_from_store(self.course_key)
     assert get_week_highlights(self.user, self.course_key,
                                week_num=1) == highlights
Exemplo n.º 8
0
    def schedules_for_bin(self):
        week_num = abs(self.day_offset) // 7
        schedules = self.get_schedules_with_target_date_by_bin_and_orgs(
            order_by='enrollment__course', )

        template_context = get_base_template_context(self.site)
        for schedule in schedules:
            enrollment = schedule.enrollment
            course = schedule.enrollment.course
            user = enrollment.user

            # (Weekly) Course Updates are only for Instructor-paced courses.
            # See CourseNextSectionUpdate for Self-paced updates.
            if course.self_paced:
                continue

            try:
                week_highlights = get_week_highlights(user,
                                                      enrollment.course_id,
                                                      week_num)
            except CourseUpdateDoesNotExist:
                LOG.warning(
                    'Weekly highlights for user {} in week {} of course {} does not exist or is disabled'
                    .format(user, week_num, enrollment.course_id))
                # continue to the next schedule, don't yield an email for this one
            else:
                unsubscribe_url = None
                if (COURSE_UPDATE_SHOW_UNSUBSCRIBE_WAFFLE_SWITCH.is_enabled()
                        and 'bulk_email_optout'
                        in settings.ACE_ENABLED_POLICIES):
                    unsubscribe_url = reverse('bulk_email_opt_out',
                                              kwargs={
                                                  'token':
                                                  UsernameCipher.encrypt(
                                                      user.username),
                                                  'course_id':
                                                  str(enrollment.course_id),
                                              })

                template_context.update({
                    'course_name':
                    schedule.enrollment.course.display_name,
                    'course_url':
                    _get_trackable_course_home_url(enrollment.course_id),
                    'week_num':
                    week_num,
                    'week_highlights':
                    week_highlights,

                    # This is used by the bulk email optout policy
                    'course_ids': [str(enrollment.course_id)],
                    'unsubscribe_url':
                    unsubscribe_url,
                })
                template_context.update(
                    _get_upsell_information_for_schedule(user, schedule))

                yield (user,
                       schedule.enrollment.course.closest_released_language,
                       template_context)
    def test_get_highlights_without_module(self, mock_get_module):
        mock_get_module.return_value = None

        with self.store.bulk_operations(self.course_key):
            self._create_chapter(highlights=['Test highlight'])

        with self.assertRaisesRegex(CourseUpdateDoesNotExist,
                                    'Course module .* not found'):
            get_week_highlights(self.user, self.course_key, 1)

        yesterday = datetime.datetime.utcnow() - datetime.timedelta(days=1)
        today = datetime.datetime.utcnow()
        with self.assertRaisesRegex(CourseUpdateDoesNotExist,
                                    'Course module .* not found'):
            get_next_section_highlights(self.user, self.course_key, yesterday,
                                        today.date())
Exemplo n.º 10
0
    def schedules_for_bin(self):
        week_num = abs(self.day_offset) / 7
        schedules = self.get_schedules_with_target_date_by_bin_and_orgs(
            order_by='enrollment__course',
        )

        template_context = get_base_template_context(self.site)
        for schedule in schedules:
            enrollment = schedule.enrollment
            user = enrollment.user

            try:
                week_highlights = get_week_highlights(user, enrollment.course_id, week_num)
            except CourseUpdateDoesNotExist:
                LOG.exception(
                    'Weekly highlights for user {} in week {} of course {} does not exist or is disabled'.format(
                        user, week_num, enrollment.course_id
                    )
                )

            template_context.update({
                'course_name': schedule.enrollment.course.display_name,
                'course_url': _get_trackable_course_home_url(enrollment.course_id),

                'week_num': week_num,
                'week_highlights': week_highlights,

                # This is used by the bulk email optout policy
                'course_ids': [str(enrollment.course_id)],
            })
            template_context.update(_get_upsell_information_for_schedule(user, schedule))

            yield (user, schedule.enrollment.course.closest_released_language, template_context)
Exemplo n.º 11
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,
     )
Exemplo n.º 12
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)
    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)
 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,
     )
Exemplo n.º 15
0
    def schedules_for_bin(self):
        week_num = abs(self.day_offset) / 7
        schedules = self.get_schedules_with_target_date_by_bin_and_orgs(
            order_by='enrollment__course', )

        template_context = get_base_template_context(self.site)
        for schedule in schedules:
            enrollment = schedule.enrollment
            user = enrollment.user

            try:
                week_highlights = get_week_highlights(user,
                                                      enrollment.course_id,
                                                      week_num)
            except CourseUpdateDoesNotExist:
                continue

            course_id_str = str(enrollment.course_id)
            template_context.update({
                'course_name':
                schedule.enrollment.course.display_name,
                'course_url':
                absolute_url(self.site,
                             reverse('course_root', args=[course_id_str])),
                'week_num':
                week_num,
                'week_highlights':
                week_highlights,

                # This is used by the bulk email optout policy
                'course_ids': [course_id_str],
            })
            template_context.update(
                _get_upsell_information_for_schedule(user, schedule))

            yield (user, schedule.enrollment.course.language, template_context)
Exemplo n.º 16
0
 def test_empty_course_raises_exception(self):
     with pytest.raises(CourseUpdateDoesNotExist):
         get_week_highlights(self.user, self.course_key, week_num=1)
Exemplo n.º 17
0
 def test_non_existent_course_raises_exception(self):
     nonexistent_course_key = self.course_key.replace(run='no_such_run')
     with pytest.raises(CourseUpdateDoesNotExist):
         get_week_highlights(self.user, nonexistent_course_key, week_num=1)
 def test_non_existent_course_raises_exception(self):
     nonexistent_course_key = self.course_key.replace(run='no_such_run')
     with self.assertRaises(CourseUpdateDoesNotExist):
         get_week_highlights(self.user, nonexistent_course_key, week_num=1)
 def test_empty_course_raises_exception(self):
     with self.assertRaises(CourseUpdateDoesNotExist):
         get_week_highlights(self.user, self.course_key, week_num=1)