def test_modify_comment_publicity(self): """ Assert that a modification made to the `is_public` or `is_removed` properties of a comment result in changes to the comment count of the content object. """ # Create a new public comment on the publishable comment = self._create_comment() tools.assert_equals(comments.get_model()._default_manager.count(), 1) tools.assert_equals(comments.get_model()._default_manager.filter(is_public=True, is_removed=False).count(), 1) # Assert that the comment count key on the publishable was set correctly to 1 tools.assert_equals( int(client.get(self._build_publishable_comment_count_key(self.publishable))), 1 ) # Update this comment (and change "publicity" of it) comment.is_public = False comment.save() # Assert that the comment count key on the publishable has been updated to reflect # the fact that there are 0 public comments associated to it. tools.assert_equals( int(client.get(self._build_publishable_comment_count_key(self.publishable))), 0 )
def test_no_change_to_comment_publicity(self): """ Assert that no change made to the `is_public` or `is_removed` properties of a comment result in no changes to the comment count or last comment keys of the content object. """ # Create a new public comment on the publishable comment = self._create_comment() tools.assert_equals(comments.get_model()._default_manager.count(), 1) tools.assert_equals(comments.get_model()._default_manager.filter(is_public=True, is_removed=False).count(), 1) # Assert that the comment count key on the publishable was set correctly to 1 tools.assert_equals( int(client.get(self._build_publishable_comment_count_key(self.publishable))), 1 ) # Update this comment (but do not change "publicity") and assert that # nothing has changed regarding the comment count on the publishable comment.comment = 'New comment text' tools.assert_true(comment.is_public) tools.assert_false(comment.is_removed) comment.save() # Assert that the comment count key on the publishable is still set correctly to 1 tools.assert_equals( int(client.get(self._build_publishable_comment_count_key(self.publishable))), 1 )
def __len__(self): if client and not self.ids: return int(client.get(COMCOUNT_KEY % (self.ctype.pk, self.object_pk)) or 0) cnt = cache.get(self._count_cache_key()) if cnt is None: cnt = self.get_query_set().count() cache.set(self._count_cache_key(), cnt, self.CACHE_TIMEOUT) return int(cnt)
def test_aa(self): day = datetime.now().strftime('%Y%m%d') create_comment(self.publishable, self.publishable.content_type, user_name='kvbik', submit_date=utc_localize(datetime(2010, 10, 10, 10, 10, 10))) ct_id = self.publishable.content_type_id tools.assert_equals(set([ 'slidingccount:WINDOWS', 'slidingccount:KEYS', 'comcount:2', 'lastcom:2', 'slidingccount:2', 'comcount:c:1', 'comcount:c:2', 'lastcom:c:1', 'lastcom:c:2', 'slidingccount:c:1', 'slidingccount:c:2', 'lastcom:d:1', 'lastcom:d:2', 'comcount:d:1', 'comcount:d:2', 'slidingccount:d:1', 'slidingccount:d:2', 'lastcom:ct:%d' % ct_id, 'comcount:ct:%d' % ct_id, 'slidingccount:ct:%d' % ct_id, 'lastcom:pub:%d:1' % ct_id, 'comcount:pub:%d:1' % ct_id, 'slidingccount:2:%s' % day, 'slidingccount:c:1:%s' % day, 'slidingccount:c:2:%s' % day, 'slidingccount:d:1:%s' % day, 'slidingccount:d:2:%s' % day, 'slidingccount:ct:%d:%s' % (ct_id, day), ]), set(client.keys('*'))) if use_tz: # timestamps are stored in utc time tstamp = '1286705410.0' else: tstamp = '1286698210.0' tools.assert_equals({'submit_date': tstamp, 'user_id': '', 'username': '******', 'comment': '', 'url': ''}, client.hgetall('lastcom:pub:%d:1' % ct_id)) tools.assert_equals('1', client.get('comcount:pub:%d:1' % ct_id))
def publishable_published(publishable, **kwargs): cnt = client.get(COMCOUNT_KEY % (publishable.content_type_id, publishable.pk)) lastcom = client.hgetall(LASTCOM_KEY % (publishable.content_type_id, publishable.pk)) pipe = client.pipeline() if cnt is None: cnt = 0 if Listing.objects.get_listing_handler(MOST_COMMENTED_LH, fallback=False): Listing.objects.get_listing_handler(MOST_COMMENTED_LH).add_publishable(publishable.category, publishable, cnt, pipe=pipe, commit=False) if lastcom and Listing.objects.get_listing_handler(LAST_COMMENTED_LH, fallback=False): Listing.objects.get_listing_handler(LAST_COMMENTED_LH).add_publishable(publishable.category, publishable, lastcom['submit_date'], pipe=pipe, commit=False) pipe.execute()