Commit 8ed247b3 by Nimisha Asthagiri

Merge pull request #6662 from edx/mobile/MA-227

MA-227 Mobile announcements sort order correction.
parents 8394fb71 caee3331
......@@ -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": "<a href=\"/static/\">foo</a>",
"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": "<a href=\"/static/\">Update" + str(num) + "</a>",
"status": CourseInfoModule.STATUS_VISIBLE
}
)
else:
update_data = u"<ol><li><h2>Date</h2><a href=\"/static/\">foo</a></li></ol>"
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 += "<li><h2>Date" + str(num) + "</h2><a href=\"/static/\">Update" + str(num) + "</a></li>"
course_updates.data = u"<ol>" + update_data + "</ol>"
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):
"""
......
......@@ -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
......
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