Guard highlights against null module
Sometimes a course module will not exist and was causing exceptions in our weekly highlights mail code. This will hopefully guard against that a bit better.
This commit is contained in:
@@ -124,9 +124,12 @@ def _get_course_module(course_descriptor, user):
|
||||
field_data_cache = FieldDataCache.cache_for_descriptor_descendents(
|
||||
course_descriptor.id, user, course_descriptor, depth=1, read_only=True,
|
||||
)
|
||||
return get_module_for_descriptor(
|
||||
course_module = get_module_for_descriptor(
|
||||
user, request, course_descriptor, field_data_cache, course_descriptor.id, course=course_descriptor,
|
||||
)
|
||||
if not course_module:
|
||||
raise CourseUpdateDoesNotExist('Course module {} not found'.format(course_descriptor.id))
|
||||
return course_module
|
||||
|
||||
|
||||
def _section_has_highlights(section):
|
||||
@@ -134,10 +137,7 @@ def _section_has_highlights(section):
|
||||
|
||||
|
||||
def _get_sections_with_highlights(course_module):
|
||||
if course_module:
|
||||
return list(filter(_section_has_highlights, course_module.get_children()))
|
||||
else:
|
||||
return []
|
||||
return list(filter(_section_has_highlights, course_module.get_children()))
|
||||
|
||||
|
||||
def _get_highlights_for_week(sections, week_num, course_key):
|
||||
|
||||
@@ -157,3 +157,19 @@ class TestContentHighlights(ModuleStoreTestCase):
|
||||
)
|
||||
with self.assertRaises(CourseUpdateDoesNotExist):
|
||||
get_next_section_highlights(self.user, self.course_key, yesterday, tomorrow.date())
|
||||
|
||||
@override_waffle_flag(COURSE_UPDATE_WAFFLE_FLAG, True)
|
||||
@mock.patch('lms.djangoapps.courseware.module_render.get_module_for_descriptor')
|
||||
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())
|
||||
|
||||
Reference in New Issue
Block a user