diff --git a/lms/djangoapps/mobile_api/course_info/tests.py b/lms/djangoapps/mobile_api/course_info/tests.py
index ad8892533b..3dfb44b757 100644
--- a/lms/djangoapps/mobile_api/course_info/tests.py
+++ b/lms/djangoapps/mobile_api/course_info/tests.py
@@ -73,31 +73,43 @@ class TestUpdates(MobileAPITestCase, MobileAuthTestMixin, MobileEnrolledCourseAc
)
# store content in Updates item (either new or old format)
+ num_updates = 3
if new_format:
- course_update_data = {
- "id": 1,
- "date": "Some date",
- "content": "foo",
- "status": CourseInfoModule.STATUS_VISIBLE
- }
- course_updates.items = [course_update_data]
+ for num in range(1, num_updates + 1):
+ course_updates.items.append(
+ {
+ "id": num,
+ "date": "Date" + str(num),
+ "content": "Update" + str(num) + "",
+ "status": CourseInfoModule.STATUS_VISIBLE
+ }
+ )
else:
- update_data = u"
Date
foo
"
- course_updates.data = update_data
+ update_data = ""
+ # old format stores the updates with the newest first
+ for num in range(num_updates, 0, -1):
+ update_data += "Date" + str(num) + "
Update" + str(num) + ""
+ course_updates.data = u"" + update_data + "
"
modulestore().update_item(course_updates, self.user.id)
# call API
response = self.api_response()
- content = response.data[0]["content"] # pylint: disable=maybe-no-member
# verify static URLs are replaced in the content returned by the API
- self.assertNotIn("\"/static/", content)
+ self.assertNotIn("\"/static/", response.content)
# verify static URLs remain in the underlying content
underlying_updates = modulestore().get_item(updates_usage_key)
underlying_content = underlying_updates.items[0]['content'] if new_format else underlying_updates.data
self.assertIn("\"/static/", underlying_content)
+ # verify content and sort order of updates (most recent first)
+ for num in range(1, num_updates + 1):
+ update_data = response.data[num_updates - num] # pylint: disable=maybe-no-member
+ self.assertEquals(num, update_data['id'])
+ self.assertEquals("Date" + str(num), update_data['date'])
+ self.assertIn("Update" + str(num), update_data['content'])
+
class TestHandouts(MobileAPITestCase, MobileAuthTestMixin, MobileEnrolledCourseAccessTestMixin):
"""
diff --git a/lms/djangoapps/mobile_api/course_info/views.py b/lms/djangoapps/mobile_api/course_info/views.py
index b0674b7be3..87bd97ecc0 100644
--- a/lms/djangoapps/mobile_api/course_info/views.py
+++ b/lms/djangoapps/mobile_api/course_info/views.py
@@ -39,7 +39,7 @@ class CourseUpdatesList(generics.ListAPIView):
@mobile_course_access()
def list(self, request, course, *args, **kwargs):
course_updates_module = get_course_info_section_module(request, course, 'updates')
- update_items = list(reversed(get_course_update_items(course_updates_module)))
+ update_items = get_course_update_items(course_updates_module)
updates_to_show = [
update for update in update_items