def test_sort(self): """Check sorting if ``use_original_date`` is ``False``.""" sort_newest = utils.BestDateSort() sort_oldest = utils.BestDateSort(descending=False) self.site_settings.use_original_date = False self.site_settings.save() expected_asc = sorted(list(Video.objects.all()), key=self.key_without_original) expected_desc = sorted(list(Video.objects.all()), key=self.key_without_original, reverse=True) results = list(sort_oldest.sort(Video.objects.all())) self.assertEqual(results, expected_asc) results = [r.object for r in sort_oldest.sort(SearchQuerySet())] self.assertEqual(results, expected_asc) results = list(sort_newest.sort(Video.objects.all())) self.assertEqual(results, expected_desc) results = [r.object for r in sort_newest.sort(SearchQuerySet())] self.assertEqual(results, expected_desc)
def setUp(self): BaseTestCase.setUp(self) self._clear_index() date1_1 = datetime.now() - timedelta(7) date1_2 = datetime.now() - timedelta(1) date2 = datetime.now() date3 = datetime.now() - timedelta(3) f = "%Y/%m/%d" self.video1 = self.create_video( name="%s - %s" % (date1_1.strftime(f), date1_2.strftime(f)), when_approved=date1_1, when_published=date1_2) self.video2 = self.create_video(name="%s - %s" % (date2.strftime(f), date2.strftime(f)), when_approved=date2, when_published=date2) self.video3 = self.create_video(name="%s - %s" % (date3.strftime(f), date3.strftime(f)), when_approved=date3, when_published=date3) self.sort = utils.BestDateSort() self.site_location = SiteLocation.objects.get_current()