'Tests sorting queue object.'

def test_do_sort_queue_object(self):

    rf = RequestFactory()
    url = reverse('reviewers.apps.queue_rereview')
    earlier_rrq = RereviewQueue.objects.create(addon=self.apps[0])
    later_rrq = RereviewQueue.objects.create(addon=self.apps[1])
    later_rrq.created += timedelta(days=1)
    later_rrq.save()
    request = rf.get(url, {'sort': 'created'})
    apps = ReviewersQueuesHelper(request).sort(RereviewQueue.objects.all())
    eq_([earlier_rrq.addon, later_rrq.addon], list(apps))
    request = rf.get(url, {'sort': 'created', 'order': 'desc'})
    apps = ReviewersQueuesHelper(request).sort(RereviewQueue.objects.all())
    eq_([later_rrq.addon, earlier_rrq.addon], list(apps))
    request = rf.get(url, {'sort': 'name', 'order': 'asc'})
    apps = ReviewersQueuesHelper(request).sort(RereviewQueue.objects.all())
    eq_([later_rrq.addon, earlier_rrq.addon], list(apps))
    request = rf.get(url, {'sort': 'name', 'order': 'desc'})
    apps = ReviewersQueuesHelper(request).sort(RereviewQueue.objects.all())
    eq_([earlier_rrq.addon, later_rrq.addon], list(apps))
