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
def test_staff_only(self): with self.store.bulk_operations(self.course_key): self._create_chapter( highlights=["I'm a secret!"], visible_to_staff_only=True, ) assert 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_course_with_no_highlights(self): with self.store.bulk_operations(self.course_key): self._create_chapter(display_name="Week 1") self._create_chapter(display_name="Week 2") self.course = self.store.get_course(self.course_key) # lint-amnesty, pylint: disable=attribute-defined-outside-init assert len(self.course.get_children()) == 2 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_course_with_highlights(self): with self.store.bulk_operations(self.course_key): self._create_chapter(highlights=['a', 'b', 'á']) self._create_chapter(highlights=[]) self._create_chapter(highlights=['skipped a week']) assert course_has_highlights_from_store(self.course_key) assert get_week_highlights(self.user, self.course_key, week_num=1) == ['a', 'b', 'á'] assert get_week_highlights(self.user, self.course_key, week_num=2) == ['skipped a week'] with pytest.raises(CourseUpdateDoesNotExist): get_week_highlights(self.user, self.course_key, week_num=3)
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. """ has_highlights = enrollment.course_overview.has_highlights if has_highlights is None: # old course that doesn't have this info cached in the overview has_highlights = course_has_highlights_from_store(enrollment.course_id) if has_highlights: return ScheduleExperience.EXPERIENCES.course_updates else: return ScheduleExperience.EXPERIENCES.default
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, )