Exemple #1
0
    def test_scalability(self):
        '''
        Test if everything works if aggregating more than 50 activities
        in one aggregated activity
        '''
        notification_feed = NotificationFeed(self.bogus_user.id)
        notification_feed.delete()

        love = Love.objects.all()[:10][0]
        activities = []
        activity = love.create_activity()
        for x in range(110):
            activity = copy.deepcopy(activity)
            activity.extra_context['entity_id'] = x
            activities.append(activity)

        # add them all
        notification_feed.add_many(activities)

        # verify that our feed size doesn't escalate
        for aggregated in notification_feed[:notification_feed.max_length]:
            full_activities = len(aggregated.activities)
            activity_count = aggregated.activity_count
            self.assertEqual(full_activities, 99)
            self.assertEqual(activity_count, 110)
            actor_count = aggregated.actor_count
            self.assertLess(actor_count, 110)

        size = notification_feed.size()
        self.assertLess(size, 6000)
Exemple #2
0
    def test_scalability(self):
        '''
        Test if everything works if aggregating more than 50 activities
        in one aggregated activity
        '''
        notification_feed = NotificationFeed(self.bogus_user.id)
        notification_feed.delete()

        love = Love.objects.all()[:10][0]
        activities = []
        activity = love.create_activity()
        for x in range(110):
            activity = copy.deepcopy(activity)
            activity.extra_context['entity_id'] = x
            activities.append(activity)

        # add them all
        notification_feed.add_many(activities)

        # verify that our feed size doesn't escalate
        for aggregated in notification_feed[:notification_feed.max_length]:
            full_activities = len(aggregated.activities)
            activity_count = aggregated.activity_count
            self.assertEqual(full_activities, 99)
            self.assertEqual(activity_count, 110)
            actor_count = aggregated.actor_count
            self.assertLess(actor_count, 110)

        size = notification_feed.size()
        self.assertLess(size, 6000)
Exemple #3
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)
Exemple #4
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)
Exemple #5
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())
Exemple #6
0
    def test_actor_count(self):
        love = Love.objects.all()[:1][0]
        feed = NotificationFeed(13)
        # setup the activities, all in the same aggregated activity
        activities = []
        feed.delete()
        for x in range(150):
            activity = Activity(love.user, LoveVerb, love, love.user,
                                time=love.created_at, extra_context=dict(x=x))
            activities.append(activity)

        # now the fast insert
        self.assertEqual(int(feed.count()), 0)
        feed.add_many(activities)
        self.assertEqual(int(feed.count()), 1)

        aggregated_activity = feed[:1][0]
        # test our Guesstimate
        self.assertEqual(aggregated_activity.minimized_activities, 51)
        self.assertEqual(aggregated_activity.actor_count, 52)
Exemple #7
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())
Exemple #8
0
    def test_actor_count(self):
        love = Love.objects.all()[:1][0]
        feed = NotificationFeed(13)
        # setup the activities, all in the same aggregated activity
        activities = []
        feed.delete()
        for x in range(150):
            activity = Activity(love.user,
                                LoveVerb,
                                love,
                                love.user,
                                time=love.created_at,
                                extra_context=dict(x=x))
            activities.append(activity)

        # now the fast insert
        self.assertEqual(int(feed.count()), 0)
        feed.add_many(activities)
        self.assertEqual(int(feed.count()), 1)

        aggregated_activity = feed[:1][0]
        # test our Guesstimate
        self.assertEqual(aggregated_activity.minimized_activities, 51)
        self.assertEqual(aggregated_activity.actor_count, 52)