Commit c51bcdbf by sanfordstudent

Merge pull request #11418 from edx/sstudent/MA-1918-handle-no-handouts

MA-1918 returning None for courses with no handouts
parents 74bdef1e f88e5bc1
...@@ -116,7 +116,19 @@ class TestHandouts(MobileAPITestCase, MobileAuthTestMixin, MobileCourseAccessTes ...@@ -116,7 +116,19 @@ class TestHandouts(MobileAPITestCase, MobileAuthTestMixin, MobileCourseAccessTes
with self.store.branch_setting(ModuleStoreEnum.Branch.draft_preferred, self.course.id): with self.store.branch_setting(ModuleStoreEnum.Branch.draft_preferred, self.course.id):
self.store.delete_item(handouts_usage_key, self.user.id) self.store.delete_item(handouts_usage_key, self.user.id)
self.api_response(expected_response_code=404) response = self.api_response(expected_response_code=200)
self.assertIsNone(response.data['handouts_html'])
def test_empty_handouts(self):
self.login_and_enroll()
# set handouts to empty tags
handouts_usage_key = self.course.id.make_usage_key('course_info', 'handouts')
underlying_handouts = self.store.get_item(handouts_usage_key)
underlying_handouts.data = "<ol></ol>"
self.store.update_item(underlying_handouts, self.user.id)
response = self.api_response(expected_response_code=200)
self.assertIsNone(response.data['handouts_html'])
def test_handouts_static_rewrites(self): def test_handouts_static_rewrites(self):
self.login_and_enroll() self.login_and_enroll()
......
...@@ -21,7 +21,7 @@ class CourseUpdatesList(generics.ListAPIView): ...@@ -21,7 +21,7 @@ class CourseUpdatesList(generics.ListAPIView):
**Example Request** **Example Request**
GET /api/mobile/v0.5/course_info/{organization}/{course_number}/{course_run}/updates GET /api/mobile/v0.5/course_info/{course_id}/updates
**Response Values** **Response Values**
...@@ -65,7 +65,7 @@ class CourseHandoutsList(generics.ListAPIView): ...@@ -65,7 +65,7 @@ class CourseHandoutsList(generics.ListAPIView):
**Example Request** **Example Request**
GET /api/mobile/v0.5/course_info/{organization}/{course_number}/{course_run}/handouts GET /api/mobile/v0.5/course_info/{course_id}/handouts
**Response Values** **Response Values**
...@@ -79,13 +79,17 @@ class CourseHandoutsList(generics.ListAPIView): ...@@ -79,13 +79,17 @@ class CourseHandoutsList(generics.ListAPIView):
def list(self, request, course, *args, **kwargs): def list(self, request, course, *args, **kwargs):
course_handouts_module = get_course_info_section_module(request, request.user, course, 'handouts') course_handouts_module = get_course_info_section_module(request, request.user, course, 'handouts')
if course_handouts_module: if course_handouts_module:
handouts_html = course_handouts_module.data if course_handouts_module.data == "<ol></ol>":
handouts_html = replace_static_urls( handouts_html = None
handouts_html, else:
course_id=course.id, handouts_html = course_handouts_module.data
static_asset_path=course.static_asset_path) handouts_html = replace_static_urls(
handouts_html = make_static_urls_absolute(self.request, handouts_html) handouts_html,
course_id=course.id,
static_asset_path=course.static_asset_path
)
handouts_html = make_static_urls_absolute(self.request, handouts_html)
return Response({'handouts_html': handouts_html}) return Response({'handouts_html': handouts_html})
else: else:
# course_handouts_module could be None if there are no handouts # course_handouts_module could be None if there are no handouts
raise Http404(u"No handouts for {}".format(unicode(course.id))) return Response({'handouts_html': None})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment