def test_follow_disabled(self): ''' Verify that follows don't show up when you disable them in the settings ''' from user.models import UserNotificationSetting # disable the follow notifications user_id = self.bogus_user.id self.set_setting( user_id, FollowVerb, dict(notify_mobile=False, enabled=False)) # verify that we disabled enabled = UserNotificationSetting.objects.enabled_for( user_id, FollowVerb) self.assertFalse(enabled) notification_feedly = NotificationFeedly() follows = Follow.objects.all()[:10] # clear the feed notification_feed = NotificationFeed(user_id) notification_feed.delete() # make sure that notifications for follows don't show up for follow in follows: follow.user_id = self.bogus_user2.id follow.target_id = user_id follow.created_at = datetime.datetime.now() activity = follow.create_activity() feed = notification_feedly._follow(follow) if feed: assert not feed.contains(activity) # the count should be zero self.assertEqual(notification_feed.count_unseen(), 0)
def test_follow_disabled(self): ''' Verify that follows don't show up when you disable them in the settings ''' from user.models import UserNotificationSetting # disable the follow notifications user_id = self.bogus_user.id self.set_setting(user_id, FollowVerb, dict(notify_mobile=False, enabled=False)) # verify that we disabled enabled = UserNotificationSetting.objects.enabled_for( user_id, FollowVerb) self.assertFalse(enabled) notification_feedly = NotificationFeedly() follows = Follow.objects.all()[:10] # clear the feed notification_feed = NotificationFeed(user_id) notification_feed.delete() # make sure that notifications for follows don't show up for follow in follows: follow.user_id = self.bogus_user2.id follow.target_id = user_id follow.created_at = datetime.datetime.now() activity = follow.create_activity() feed = notification_feedly._follow(follow) if feed: assert not feed.contains(activity) # the count should be zero self.assertEqual(notification_feed.count_unseen(), 0)
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_follow(self): notification_feedly = NotificationFeedly() follows = Follow.objects.all()[:10] notification_feed = NotificationFeed(self.bogus_user.id) notification_feed.delete() for follow in follows: follow.user_id = self.bogus_user2.id follow.target_id = self.bogus_user.id follow.created_at = datetime.datetime.now() activity = follow.create_activity() feed = notification_feedly._follow(follow) assert feed.contains(activity) # influencer feed self.assertEqual(notification_feed.count_unseen(), 1)
def test_mark_all(self): loves = Love.objects.all()[:3] feed = NotificationFeed(13) feed.delete() activities = [l.create_activity() for l in loves] # so we have something to compare to aggregator = RecentVerbAggregator() aggregated_activities = aggregator.aggregate(activities) # insert into the feed feed.add_many(activities) 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) # Activity gets inserted and marked read # a new activity is appended which updates the last_seen field # the activity is now not seen # # however mark_all will not update # first insert activity = activities[0] activity.time = datetime.datetime.now() feed.add(activity) self.assertNotEqual(feed.count_unseen(), 0) feed.mark_all(seen=True) self.assertEqual(feed.count_unseen(), 0) # check if an updated activity still gets marked import time time.sleep(1) activity.time = datetime.datetime.now() # hack to make sure its duplicate activity.extra_context['foo'] = 'bar' feed.add(activity) self.assertEqual(feed.count_unseen(), 1) # mark as read again feed.mark_all(seen=True) self.assertEqual(feed.count_unseen(), 0)
def test_mark_all(self): loves = Love.objects.all()[:3] feed = NotificationFeed(13) feed.delete() activities = [l.create_activity() for l in loves] # so we have something to compare to aggregator = RecentVerbAggregator() aggregated_activities = aggregator.aggregate(activities) # insert into the feed feed.add_many(activities) 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) # Activity gets inserted and marked read # a new activity is appended which updates the last_seen field # the activity is now not seen # # however mark_all will not update # verify that we have zero unseen after mark all feed.mark_all(seen=True) self.assertEqual(feed.count_unseen(), 0) # an update to an activity should kick the count back to one activity = activities[0] # check if an updated activity still gets marked import time time.sleep(1) activity.time = datetime.datetime.now() # hack to make sure its not duplicate activity.extra_context['foo'] = 'bar' feed.add(activity) self.assertEqual(feed.count_unseen(), 1) # mark as read again feed.mark_all(seen=True) self.assertEqual(feed.count_unseen(), 0)