'Test that the list of newly created courses are properly sorted to show the most
recent enrollments first.'

def test_enrollments_sorted_most_recent(self):

    self._configure_message_timeout(600)
    courses = []
    for (idx, seconds_past) in zip(range(2, 6), [5, 10, 15, 20]):
        course_location = locator.CourseLocator('Org{num}'.format(num=idx), 'Course{num}'.format(num=idx), 'Run{num}'.format(num=idx))
        (course, enrollment) = self._create_course_and_enrollment(course_location)
        enrollment.created = (datetime.datetime.now(UTC) - datetime.timedelta(seconds=seconds_past))
        enrollment.save()
        courses.append(course)
    courses_list = list(get_course_enrollments(self.student, None, []))
    self.assertEqual(len(courses_list), 6)
    recent_course_list = _get_recently_enrolled_courses(courses_list)
    self.assertEqual(len(recent_course_list), 5)
    self.assertEqual(recent_course_list[1].course.id, courses[0].id)
    self.assertEqual(recent_course_list[2].course.id, courses[1].id)
    self.assertEqual(recent_course_list[3].course.id, courses[2].id)
    self.assertEqual(recent_course_list[4].course.id, courses[3].id)
