Example #1
0
    def test_aggregated_feed(self):
        loves = Love.objects.all()[:10]
        feed = AggregatedFeed(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)
Example #2
0
    def test_aggregated_feed(self):
        loves = Love.objects.all()[:10]
        feed = AggregatedFeed(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)
Example #3
0
 def generate_aggregated_activities(self, diff=0):
     aggregator = RecentVerbAggregator()
     activities = []
     for x in range(1, 20 + diff):
         activity = Activity(x, LoveVerb, Pin(id=x))
         activities.append(activity)
     aggregated_activities = aggregator.aggregate(activities)
     return aggregated_activities
Example #4
0
 def generate_aggregated_activities(self, diff=0):
     aggregator = RecentVerbAggregator()
     activities = []
     for x in range(1, 20 + diff):
         activity = Activity(x, LoveVerb, Pin(id=x))
         activities.append(activity)
     aggregated_activities = aggregator.aggregate(activities)
     return aggregated_activities
Example #5
0
 def setUp(self):
     from feedly.verbs.base import Love as LoveVerb
     self.serializer = self.serialization_class()
     self.activity = FakeActivity(
         1, LoveVerb, 1, 1, datetime.datetime.now(), {})
     aggregator = RecentVerbAggregator()
     self.aggregated_activity = aggregator.aggregate([self.activity])[0]
     self.args = ()
     self.kwargs = {}
Example #6
0
 def setUp(self):
     from feedly.verbs.base import Love as LoveVerb
     self.serializer = self.serialization_class()
     self.activity = FakeActivity(1, LoveVerb, 1, 1,
                                  datetime.datetime.now(), {})
     aggregator = RecentVerbAggregator()
     self.aggregated_activity = aggregator.aggregate([self.activity])[0]
     self.args = ()
     self.kwargs = {}
Example #7
0
 def test_aggregated_remove(self):
     activity_object = Pin(id=1)
     activities = []
     for x in range(1, 101):
         activity = Activity(x, LoveVerb, activity_object)
         activities.append(activity)
     aggregator = RecentVerbAggregator()
     aggregated_activities = aggregator.aggregate(activities)
     aggregated = aggregated_activities[0]
     for activity in activities:
         try:
             aggregated.remove(activity)
         except (ActivityNotFound, ValueError):
             pass
     self.assertEqual(len(aggregated.activities), 1)
     self.assertEqual(aggregated.activity_count, 72)
Example #8
0
 def test_aggregated_remove(self):
     activity_object = Pin(id=1)
     activities = []
     for x in range(1, 101):
         activity = Activity(x, LoveVerb, activity_object)
         activities.append(activity)
     aggregator = RecentVerbAggregator()
     aggregated_activities = aggregator.aggregate(activities)
     aggregated = aggregated_activities[0]
     for activity in activities:
         try:
             aggregated.remove(activity)
         except (ActivityNotFound, ValueError):
             pass
     self.assertEqual(len(aggregated.activities), 1)
     self.assertEqual(aggregated.activity_count, 72)
Example #9
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

        # 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)
Example #10
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)
Example #11
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())
Example #12
0
    def test_aggregated_properties(self):
        activity_object = Pin(id=1)
        activities = []
        for x in range(1, 101):
            activity = Activity(x, LoveVerb, activity_object)
            activities.append(activity)
        aggregator = RecentVerbAggregator()
        aggregated_activities = aggregator.aggregate(activities)
        aggregated = aggregated_activities[0]

        self.assertEqual(aggregated.verbs, [LoveVerb])
        self.assertEqual(aggregated.verb, LoveVerb)
        self.assertEqual(aggregated.actor_count, 100)
        self.assertEqual(aggregated.minimized_activities, 85)
        self.assertEqual(aggregated.other_actor_count, 98)
        self.assertEqual(aggregated.activity_count, 100)
        self.assertEqual(aggregated.object_ids, [1])
        # the other ones should be dropped
        self.assertEqual(aggregated.actor_ids, range(86, 101))
        self.assertEqual(aggregated.is_seen(), False)
        self.assertEqual(aggregated.is_read(), False)
Example #13
0
    def test_aggregated_properties(self):
        activities = []
        for x in range(1, 101):
            activity_object = Pin(id=x)
            activity = Activity(x, LoveVerb, activity_object)
            activities.append(activity)
        aggregator = RecentVerbAggregator()
        aggregated_activities = aggregator.aggregate(activities)
        aggregated = aggregated_activities[0]

        self.assertEqual(aggregated.verbs, [LoveVerb])
        self.assertEqual(aggregated.verb, LoveVerb)
        self.assertEqual(aggregated.actor_count, 100)
        self.assertEqual(aggregated.minimized_activities, 85)
        self.assertEqual(aggregated.other_actor_count, 98)
        self.assertEqual(aggregated.activity_count, 100)
        self.assertEqual(aggregated.object_ids, range(86, 101))
        # the other ones should be dropped
        self.assertEqual(aggregated.actor_ids, range(86, 101))
        self.assertEqual(aggregated.is_seen(), False)
        self.assertEqual(aggregated.is_read(), False)
Example #14
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())