'Tests the sorts are correct with a priority review flagged app.'

def test_sort_with_priority_review(self):

    self.apps.append(app_factory(name='Foxkeh', status=mkt.STATUS_PENDING, is_packaged=False, version_kw={'version': '1.0'}, file_kw={'status': mkt.STATUS_PENDING}, premium_type=mkt.ADDON_FREE, priority_review=True))
    self.apps[2].update(created=self.days_ago(1))
    self.apps[2].addonuser_set.create(user=user_factory(email='redpanda@mozilla.com'))
    self.apps[2].addondevicetype_set.create(device_type=mkt.DEVICE_DESKTOP.id)
    rf = RequestFactory()
    qs = Webapp.objects.all()
    req = rf.get(self.url, {'sort': 'invalidsort', 'order': 'dontcare'})
    sorted_qs = ReviewersQueuesHelper(req).sort(qs)
    eq_(list(sorted_qs), [self.apps[2], self.apps[1], self.apps[0]])
    req = rf.get(self.url, {'sort': 'created', 'order': 'desc'})
    sorted_qs = ReviewersQueuesHelper(req).sort(qs)
    eq_(list(sorted_qs), [self.apps[2], self.apps[0], self.apps[1]])
    version_0 = self.apps[0].versions.get()
    version_0.update(nomination=days_ago(1))
    version_1 = self.apps[1].versions.get()
    version_1.update(nomination=days_ago(2))
    qs = Version.objects.filter(files__status=mkt.STATUS_PENDING, addon__disabled_by_user=False, addon__status=mkt.STATUS_PENDING).order_by('nomination', 'created').select_related('addon', 'files').no_transforms()
    req = rf.get(self.url, {'sort': 'nomination'})
    sorted_qs = ReviewersQueuesHelper(req).sort(qs, date_sort='nomination')
    eq_(list(sorted_qs), [self.apps[2], self.apps[1], self.apps[0]])
    req = rf.get(self.url, {'sort': 'nomination', 'order': 'desc'})
    sorted_qs = ReviewersQueuesHelper(req).sort(qs, date_sort='nomination')
    eq_(list(sorted_qs), [self.apps[2], self.apps[0], self.apps[1]])
    url = reverse('reviewers.apps.queue_rereview')
    earlier_rrq = RereviewQueue.objects.create(addon=self.apps[0])
    earlier_rrq.created += timedelta(days=1)
    earlier_rrq.save()
    later_rrq = RereviewQueue.objects.create(addon=self.apps[1])
    later_rrq.created += timedelta(days=2)
    later_rrq.save()
    pri_rrq = RereviewQueue.objects.create(addon=self.apps[2])
    pri_rrq.save()
    request = rf.get(url, {'sort': 'created'})
    apps = ReviewersQueuesHelper(request).sort(RereviewQueue.objects.all())
    eq_([pri_rrq.addon, earlier_rrq.addon, later_rrq.addon], list(apps))
    request = rf.get(url, {'sort': 'created', 'order': 'desc'})
    apps = ReviewersQueuesHelper(request).sort(RereviewQueue.objects.all())
    eq_([pri_rrq.addon, later_rrq.addon, earlier_rrq.addon], list(apps))
