def test_add_love(self): # disable the follow notifications user_id = self.bogus_user.id self.set_setting( user_id, LoveVerb, dict(notify_mobile=False, enabled=False)) love = Love.objects.all()[:10][0] love.created_at = datetime.datetime.now() love.influencer_id = user_id influencer_feed = NotificationFeed(user_id) love.entity.created_by_id = self.bogus_user2.id creator_feed = NotificationFeed(self.bogus_user2.id) # we want to write two notifications # someone loved your find # someone loved your love notification_feedly = NotificationFeedly() # clean slate for testing influencer_feed.delete() creator_feed.delete() # comparison activity activity = love.create_activity() notification_feedly.add_love(love) # influencer is equal to user_id and shouldnt contain the activity assert not influencer_feed.contains(activity) # creator feed should contain since the settings hasn't been disabled creator_activity = copy.deepcopy(activity) creator_activity.extra_context['find'] = True assert creator_feed.contains(creator_activity)
def test_love(self): love = Love.objects.all()[:10][0] love.created_at = datetime.datetime.now() love.influencer_id = self.bogus_user.id influencer_feed = NotificationFeed(self.bogus_user.id) love.entity.created_by_id = self.bogus_user2.id creator_feed = NotificationFeed(self.bogus_user2.id) # we want to write two notifications # someone loved your find # someone loved your love notification_feedly = NotificationFeedly() # clean slate for testing influencer_feed.delete() creator_feed.delete() # comparison activity activity = love.create_activity() notification_feedly.add_love(love) # influencer feed assert influencer_feed.contains(activity) # creator feed creator_activity = copy.deepcopy(activity) creator_activity.extra_context['find'] = True assert creator_feed.contains(creator_activity)
def test_add_love(self): # disable the follow notifications user_id = self.bogus_user.id self.set_setting(user_id, LoveVerb, dict(notify_mobile=False, enabled=False)) love = Love.objects.all()[:10][0] love.created_at = datetime.datetime.now() love.influencer_id = user_id influencer_feed = NotificationFeed(user_id) love.entity.created_by_id = self.bogus_user2.id creator_feed = NotificationFeed(self.bogus_user2.id) # we want to write two notifications # someone loved your find # someone loved your love notification_feedly = NotificationFeedly() # clean slate for testing influencer_feed.delete() creator_feed.delete() # comparison activity activity = love.create_activity() notification_feedly.add_love(love) # influencer is equal to user_id and shouldnt contain the activity assert not influencer_feed.contains(activity) # creator feed should contain since the settings hasn't been disabled creator_activity = copy.deepcopy(activity) creator_activity.extra_context['find'] = True assert creator_feed.contains(creator_activity)
def test_notification_feed(self): loves = Love.objects.all()[:10] feed = NotificationFeed(13) # slow version activities = [] feed.delete() for love in loves: activity = Activity(love.user, LoveVerb, love, love.user, time=love.created_at, extra_context=dict(hello='world')) activities.append(activity) feed.add(activity) assert feed.contains(activity) # so we have something to compare to aggregator = RecentVerbAggregator() aggregated_activities = aggregator.aggregate(activities) # check the feed feed_loves = feed[:20] self.assertEqual(len(aggregated_activities), len(feed_loves)) # now the fast version feed.delete() self.assertEqual(int(feed.count()), 0) feed.add_many(activities) for activity in activities: assert feed.contains(activity) # test if we aggregated correctly self.assertEqual(feed.count_unseen(), len(aggregated_activities)) # verify if we denormalize correctly self.assertEqual(feed.count_unseen(), feed.get_denormalized_count()) # sanity check self.assertNotEqual(feed.count_unseen(), 0) # test marking as seen or read feed.mark_all(seen=True) # verify that the new count is 0 self.assertEqual(feed.count_unseen(), 0) # verify if we denormalize correctly self.assertEqual(feed.count_unseen(), feed.get_denormalized_count())
def test_add_to_list(self): notification_feedly = NotificationFeedly() notification_feed = NotificationFeed(self.bogus_user.id) list_items = ListItem.objects.all()[:1] for list_item in list_items: list_item.entity.created_by_id = self.bogus_user.id notification_feedly.add_to_list(list_item) activity = list_item.create_activity() assert notification_feed.contains(activity)
def test_add_remove(self): ''' Try to remove an aggregated activity ''' from datetime import datetime, time, timedelta love = Love.objects.all()[:1][0] feed = NotificationFeed(13) # slow version activities = [] feed.delete() activity = love.create_activity() activities.append(activity) feed.add(activity) assert feed.contains(activity) # sticking in the same activity with a different time should fail # within the same day should fail activity.time = activity.time - timedelta(seconds=120) try: feed.add(activity) raise ValueError( 'DuplicateActivityException should have been raised') except feedly_exceptions.DuplicateActivityException, e: pass