def test_listing_gets_removed_when_publishable_marked_unpublished_even_if_not_published_yet(self): future = now() + timedelta(days=1) p = self.publishables[0] p.publish_from = future p.save() list_all_publishables_in_category_by_hour(self) p.published = False p.save() ct_id = p.content_type_id tools.assert_equals(set([ 'listing:2', 'listing:3', 'listing:c:1', 'listing:c:2', 'listing:c:3', 'listing:d:1', 'listing:d:2', 'listing:d:3', 'listing:ct:%d' % ct_id, ]), set(redis.client.keys()) ) tools.assert_equals(['%d:2' % ct_id, '%d:3' % ct_id], redis.client.zrange('listing:ct:%d' % ct_id, 0, 100)) tools.assert_equals(['%d:2' % ct_id, '%d:3' % ct_id], redis.client.zrange('listing:d:1', 0, 100)) tools.assert_equals(['%d:2' % ct_id], redis.client.zrange('listing:c:1', 0, 100))
def test_listing_save_adds_itself_to_relevant_zsets(self): list_all_publishables_in_category_by_hour(self) ct_id = self.publishables[0].content_type_id tools.assert_equals( set([ 'listing:1', 'listing:2', 'listing:3', 'listing:c:1', 'listing:c:2', 'listing:c:3', 'listing:d:1', 'listing:d:2', 'listing:d:3', 'listing:ct:%d' % ct_id, ]), set(redis.client.keys())) tools.assert_equals(['%d:3' % ct_id], redis.client.zrange('listing:3', 0, 100)) tools.assert_equals( ['%d:1' % ct_id, '%d:2' % ct_id, '%d:3' % ct_id], redis.client.zrange('listing:ct:%d' % ct_id, 0, 100)) tools.assert_equals( ['%d:1' % ct_id, '%d:2' % ct_id, '%d:3' % ct_id], redis.client.zrange('listing:d:1', 0, 100))
def test_listing_gets_removed_when_publishable_goes_unpublished(self): list_all_publishables_in_category_by_hour(self) p = self.publishables[0] p.published = False p.save() ct_id = p.content_type_id tools.assert_equals(set([ 'listing:2', 'listing:3', 'listing:c:1', 'listing:c:2', 'listing:c:3', 'listing:d:1', 'listing:d:2', 'listing:d:3', 'listing:ct:%d' % ct_id, ]), set(self.redis.keys()) ) tools.assert_equals(['%d:2' % ct_id, '%d:3' % ct_id], self.redis.zrange('listing:ct:%d' % ct_id, 0, 100)) tools.assert_equals(['%d:2' % ct_id, '%d:3' % ct_id], self.redis.zrange('listing:d:1', 0, 100)) tools.assert_equals(['%d:2' % ct_id], self.redis.zrange('listing:c:1', 0, 100))
def test_listing_delete_removes_itself_from_redis(self): list_all_publishables_in_category_by_hour(self) self.listings[1].delete() ct_id = self.publishables[0].content_type_id tools.assert_equals( set([ 'listing:1', 'listing:3', 'listing:c:1', 'listing:c:2', 'listing:c:3', 'listing:d:1', 'listing:d:2', 'listing:d:3', 'listing:ct:%d' % ct_id, ]), set(redis.client.keys())) tools.assert_equals(['%d:3' % ct_id], redis.client.zrange('listing:3', 0, 100)) tools.assert_equals(['%d:3' % ct_id], redis.client.zrange('listing:c:2', 0, 100)) tools.assert_equals(['%d:3' % ct_id], redis.client.zrange('listing:d:2', 0, 100)) tools.assert_equals(['%d:1' % ct_id, '%d:3' % ct_id], redis.client.zrange('listing:d:1', 0, 100)) tools.assert_equals(['%d:1' % ct_id], redis.client.zrange('listing:c:1', 0, 100)) tools.assert_equals(['%d:1' % ct_id, '%d:3' % ct_id], redis.client.zrange('listing:ct:%d' % ct_id, 0, 100))
def test_listing_gets_removed_when_publishable_goes_unpublished(self): list_all_publishables_in_category_by_hour(self) p = self.publishables[0] p.published = False p.save() ct_id = p.content_type_id tools.assert_equals( set([ 'listing:2', 'listing:3', 'listing:c:1', 'listing:c:2', 'listing:c:3', 'listing:d:1', 'listing:d:2', 'listing:d:3', 'listing:ct:%d' % ct_id, ]), set(redis.client.keys())) tools.assert_equals(['%d:2' % ct_id, '%d:3' % ct_id], redis.client.zrange('listing:ct:%d' % ct_id, 0, 100)) tools.assert_equals(['%d:2' % ct_id, '%d:3' % ct_id], redis.client.zrange('listing:d:1', 0, 100)) tools.assert_equals(['%d:2' % ct_id], redis.client.zrange('listing:c:1', 0, 100))
def test_listing_gets_removed_when_publishable_marked_unpublished_even_if_not_published_yet( self): future = now() + timedelta(days=1) p = self.publishables[0] p.publish_from = future p.save() list_all_publishables_in_category_by_hour(self) p.published = False p.save() ct_id = p.content_type_id tools.assert_equals( set([ 'listing:2', 'listing:3', 'listing:c:1', 'listing:c:2', 'listing:c:3', 'listing:d:1', 'listing:d:2', 'listing:d:3', 'listing:ct:%d' % ct_id, ]), set(redis.client.keys())) tools.assert_equals(['%d:2' % ct_id, '%d:3' % ct_id], redis.client.zrange('listing:ct:%d' % ct_id, 0, 100)) tools.assert_equals(['%d:2' % ct_id, '%d:3' % ct_id], redis.client.zrange('listing:d:1', 0, 100)) tools.assert_equals(['%d:2' % ct_id], redis.client.zrange('listing:c:1', 0, 100))
def test_listing_delete_removes_itself_from_redis(self): list_all_publishables_in_category_by_hour(self) self.listings[1].delete() ct_id = self.publishables[0].content_type_id tools.assert_equals(set([ 'listing:1', 'listing:3', 'listing:c:1', 'listing:c:2', 'listing:c:3', 'listing:d:1', 'listing:d:2', 'listing:d:3', 'listing:ct:%d' % ct_id, ]), set(self.redis.keys()) ) tools.assert_equals(['%d:3' % ct_id], self.redis.zrange('listing:3', 0, 100)) tools.assert_equals(['%d:3' % ct_id], self.redis.zrange('listing:c:2', 0, 100)) tools.assert_equals(['%d:3' % ct_id], self.redis.zrange('listing:d:2', 0, 100)) tools.assert_equals(['%d:1' % ct_id, '%d:3' % ct_id], self.redis.zrange('listing:d:1', 0, 100)) tools.assert_equals(['%d:1' % ct_id], self.redis.zrange('listing:c:1', 0, 100)) tools.assert_equals(['%d:1' % ct_id, '%d:3' % ct_id], self.redis.zrange('listing:ct:%d' % ct_id, 0, 100))
def test_listing_save_adds_itself_to_relevant_zsets(self): list_all_publishables_in_category_by_hour(self) ct_id = self.publishables[0].content_type_id tools.assert_equals( set( [ "listing:1", "listing:2", "listing:3", "listing:c:1", "listing:c:2", "listing:c:3", "listing:d:1", "listing:d:2", "listing:d:3", "listing:ct:%d" % ct_id, ] ), set(self.redis.keys()), ) tools.assert_equals(["%d:3" % ct_id], self.redis.zrange("listing:3", 0, 100)) tools.assert_equals( ["%d:1" % ct_id, "%d:2" % ct_id, "%d:3" % ct_id], self.redis.zrange("listing:ct:%d" % ct_id, 0, 100) ) tools.assert_equals(["%d:1" % ct_id, "%d:2" % ct_id, "%d:3" % ct_id], self.redis.zrange("listing:d:1", 0, 100))
def test_listing_save_adds_itself_to_relevant_zsets(self): list_all_publishables_in_category_by_hour(self) ct_id = self.publishables[0].content_type_id tools.assert_equals(set([ 'listing:1', 'listing:2', 'listing:3', 'listing:c:1', 'listing:c:2', 'listing:c:3', 'listing:d:1', 'listing:d:2', 'listing:d:3', 'listing:a:%d' % self.author.pk, 'listing:ct:%d' % ct_id, ]), set(self.redis.keys()) ) tools.assert_equals(['%d:1' % ct_id, '%d:2' % ct_id, '%d:3' % ct_id], self.redis.zrange('listing:a:1', 0, 100))
def test_access_to_individual_listings(self): list_all_publishables_in_category_by_hour(self) lh = Listing.objects.get_queryset_wrapper(category=self.category, children=ListingHandler.ALL, source='redis') l = lh[0] tools.assert_equals(l.publishable, self.listings[0].publishable)
def test_nested_listings(self): list_all_publishables_in_category_by_hour( self, category=self.category_nested_second) list_all_publishables_in_category_by_hour( self, category=self.category_nested) l = Listing.objects.get_listing(category=self.category_nested, children=ListingHandler.ALL) tools.assert_equals(self.listings, list(l))
def setUp(self): super(GetRelatedTestCase, self).setUp() create_basic_categories(self) create_and_place_a_publishable(self) create_and_place_more_publishables(self) Publishable.objects.all().update(category=self.publishable.category) list_all_publishables_in_category_by_hour(self, category=self.publishable.category)
def test_time_based_lh_slicing(self): list_all_publishables_in_category_by_hour(self) # Instantiate the RedisListingHandler and have it fetch all children lh = redis.TimeBasedListingHandler(self.category, ListingHandler.ALL) for offset, count in [(0, 10), (0, 1), (0, 2), (1, 2), (2, 3), (3, 3)]: partial = lh.get_listings(offset=offset, count=count) tools.assert_equals( [l.publishable for l in partial], [l.publishable for l in self.listings[offset:offset + count]])
def setUp(self): super(GetRelatedTestCase, self).setUp() create_basic_categories(self) create_and_place_a_publishable(self) create_and_place_more_publishables(self) Publishable.objects.all().update(category=self.publishable.category) list_all_publishables_in_category_by_hour( self, category=self.publishable.category)
def test_time_based_lh_slicing(self): list_all_publishables_in_category_by_hour(self) # Instantiate the RedisListingHandler and have it fetch all children lh = redis.TimeBasedListingHandler(self.category, ListingHandler.ALL) for offset, count in [(0, 10), (0, 1), (0, 2), (1, 2), (2, 3), (3, 3)]: partial = lh.get_listings(offset=offset, count=count) tools.assert_equals( [l.publishable for l in partial], [l.publishable for l in self.listings[offset:offset + count]] )
def test_author_view(self): author = Author.objects.create(slug='some-author') create_and_place_more_publishables(self) for p in self.publishables: p.authors.add(author) list_all_publishables_in_category_by_hour(self) template_loader.templates['page/author.html'] = 'page/category.html' response = self.client.get(author.get_absolute_url()) tools.assert_true('listings' in response.context) tools.assert_equals(set(p.pk for p in self.publishables), set(l.publishable.pk for l in response.context['listings']))
def setUp(self): try: import feedparser except ImportError: raise SkipTest() super(TestFeeds, self).setUp() create_basic_categories(self) create_and_place_more_publishables(self) list_all_publishables_in_category_by_hour(self) self._feeder = RSSTopCategoryListings()
def test_gets_removed_when_last_listing_is_deleted(self): list_all_publishables_in_category_by_hour(self) ct_id = self.publishables[0].content_type_id while 1: listings = self.publishables[0].listing_set.all() if len(listings): tools.ok_('%d:1' % ct_id in redis.client.zrange('listing:a:1', 0, 100)) listings[0].delete() else: tools.ok_('%d:1' % ct_id not in redis.client.zrange('listing:a:1', 0, 100)) break
def test_author_view(self): author = Author.objects.create(slug='some-author') create_and_place_more_publishables(self) for p in self.publishables: p.authors.add(author) list_all_publishables_in_category_by_hour(self) template_loader.templates['page/author.html'] = 'page/category.html' response = self.client.get(author.get_absolute_url()) tools.assert_true('listings' in response.context) tools.assert_equals( set(p.pk for p in self.publishables), set(l.publishable.pk for l in response.context['listings']))
def test_listings_dont_propagate_where_they_shouldnt(self): self.category_nested.app_data = {'ella': {'propagate_listings': False}} self.category_nested.save() # small hack to remove the cached category on Publishable for p in self.publishables: del p._category_cache list_all_publishables_in_category_by_hour(self) ct_id = self.publishables[0].content_type_id tools.assert_equals(['%d:1' % ct_id], self.redis.zrange('listing:d:1', 0, 100)) tools.assert_equals(['%d:1' % ct_id], self.redis.zrange('listing:c:1', 0, 100)) tools.assert_equals(['%d:2' % ct_id, '%d:3' % ct_id], self.redis.zrange('listing:c:2', 0, 100)) tools.assert_equals(['%d:2' % ct_id, '%d:3' % ct_id], self.redis.zrange('listing:d:2', 0, 100))
def test_gets_removed_when_last_listing_is_deleted(self): list_all_publishables_in_category_by_hour(self) ct_id = self.publishables[0].content_type_id while 1: listings = self.publishables[0].listing_set.all() if len(listings): tools.ok_('%d:1' % ct_id in redis.client.zrange('listing:a:1', 0, 100)) listings[0].delete() else: tools.ok_( '%d:1' % ct_id not in redis.client.zrange('listing:a:1', 0, 100)) break
def test_listings_dont_propagate_where_they_shouldnt(self): self.category_nested.app_data = {'ella': {'propagate_listings': False}} self.category_nested.save() # small hack to remove the cached category on Publishable for p in self.publishables: del p._category_cache list_all_publishables_in_category_by_hour(self) ct_id = self.publishables[0].content_type_id tools.assert_equals(['%d:1' % ct_id], redis.client.zrange('listing:d:1', 0, 100)) tools.assert_equals(['%d:1' % ct_id], redis.client.zrange('listing:c:1', 0, 100)) tools.assert_equals(['%d:2' % ct_id, '%d:3' % ct_id], redis.client.zrange('listing:c:2', 0, 100)) tools.assert_equals(['%d:2' % ct_id, '%d:3' % ct_id], redis.client.zrange('listing:d:2', 0, 100))
def test_not_added_when_not_published(self): ct_id = self.publishables[0].content_type_id self.publishables[0].published = False self.publishables[0].save() list_all_publishables_in_category_by_hour(self) tools.ok_('%d:1' % ct_id not in redis.client.zrange('listing:a:1', 0, 100)) self.publishables[0].published = True self.publishables[0].save() tools.ok_('%d:1' % ct_id in redis.client.zrange('listing:a:1', 0, 100)) self.publishables[0].published = False self.publishables[0].save() tools.ok_('%d:1' % ct_id not in redis.client.zrange('listing:a:1', 0, 100))
def setUp(self): super(TestListing, self).setUp() create_basic_categories(self) create_and_place_a_publishable(self) create_and_place_more_publishables(self) list_all_publishables_in_category_by_hour(self)
def test_nested_listings(self): list_all_publishables_in_category_by_hour(self, category=self.category_nested_second) list_all_publishables_in_category_by_hour(self, category=self.category_nested) l = Listing.objects.get_listing(category=self.category_nested, children=ListingHandler.ALL) tools.assert_equals(self.listings, list(l))
def setUp(self): super(TestListContentType, self).setUp() create_and_place_more_publishables(self) list_all_publishables_in_category_by_hour(self, category=self.category) self.list_content_type = ListContentType()
def setUp(self): super(TestListingTag, self).setUp() create_basic_categories(self) create_and_place_a_publishable(self) create_and_place_more_publishables(self) list_all_publishables_in_category_by_hour(self)
def setUp(self): super(TestListContentType, self).setUp() create_and_place_more_publishables(self) list_all_publishables_in_category_by_hour(self, category=self.category)