'Tests the API to get a sorted list of CCX Courses'

@ddt.data(*AUTH_ATTRS)
def test_get_sorted_list(self, auth_attr):

    num_ccx = 3
    for _ in xrange(num_ccx):
        self.make_ccx()
    all_ccx = CustomCourseForEdX.objects.all()
    all_ccx = all_ccx.order_by('id')
    self.assertEqual(len(all_ccx), num_ccx)
    title_str = 'Title    CCX    {0}'
    for (num, ccx) in enumerate(all_ccx):
        ccx.display_name = title_str.format(string.ascii_lowercase[(- (num + 1))])
        ccx.save()
    url = '{0}&order_by=display_name'.format(self.list_url_master_course)
    resp = self.client.get(url, {}, HTTP_AUTHORIZATION=getattr(self, auth_attr))
    self.assertEqual(resp.status_code, status.HTTP_200_OK)
    self.assertEqual(len(resp.data['results']), num_ccx)
    for (num, ccx) in enumerate(resp.data['results']):
        self.assertEqual(title_str.format(string.ascii_lowercase[(- (num_ccx - num))]), ccx['display_name'])
    url = '{0}&order_by=display_name&sort_order=desc'.format(self.list_url_master_course)
    resp = self.client.get(url, {}, HTTP_AUTHORIZATION=getattr(self, auth_attr))
    for (num, ccx) in enumerate(resp.data['results']):
        self.assertEqual(title_str.format(string.ascii_lowercase[(- (num + 1))]), ccx['display_name'])
