Exemple #1
0
 def test_double_finish(self):
     # validate that finish called twice acts as expected
     feed = DatabaseFallbackLoveFeed(self.bogus_user.id)
     feed.delete()
     feed.finish()
     feed.finish()
     self.assertEqual(feed.count(), 1)
Exemple #2
0
 def test_double_finish(self):
     # validate that finish called twice acts as expected
     feed = DatabaseFallbackLoveFeed(self.bogus_user.id)
     feed.delete()
     feed.finish()
     feed.finish()
     self.assertEqual(feed.count(), 1)
Exemple #3
0
 def test_finish_marker_creation(self):
     # The user's feed is empty at the moment
     feed = DatabaseFallbackLoveFeed(self.bogus_user.id)
     feed.delete()
     results = feed[:100]
     self.assertEqual(results, [])
     self.assertEqual(feed.source, 'db')
     # now try reading the data only from redis
     results = feed[:100]
     self.assertEqual(feed.source, 'redis')
     # the finish marker should be there though
     self.assertEqual(feed.count(), 1)
Exemple #4
0
 def test_finish_marker_creation(self):
     # The user's feed is empty at the moment
     feed = DatabaseFallbackLoveFeed(self.bogus_user.id)
     feed.delete()
     results = feed[:100]
     self.assertEqual(results, [])
     self.assertEqual(feed.source, 'db')
     # now try reading the data only from redis
     results = feed[:100]
     self.assertEqual(feed.source, 'redis')
     # the finish marker should be there though
     self.assertEqual(feed.count(), 1)
Exemple #5
0
    def test_follow_many_trim(self):
        follows = Follow.objects.filter(user=self.bogus_user)[:5]
        follow = follows[0]
        # reset the feed
        feed = DatabaseFallbackLoveFeed(follow.user_id)
        feed.delete()
        # do a follow
        feedly = LoveFeedly()
        max_loves = 3
        feedly.follow_many(follows, async=False, max_loves=max_loves)
        # we should only have 3 items in the feed
        feed_count = feed.count()
        self.assertEqual(feed_count, max_loves)

        # but we should fallback to the database
        feed_results = feed[:20]
        self.assertEqual(len(feed_results), 20)
Exemple #6
0
    def test_follow_many_trim(self):
        follows = Follow.objects.filter(user=self.bogus_user)[:5]
        follow = follows[0]
        # reset the feed
        feed = DatabaseFallbackLoveFeed(follow.user_id)
        feed.delete()
        # do a follow
        feedly = LoveFeedly()
        max_loves = 3
        feedly.follow_many(follows, async=False, max_loves=max_loves)
        # we should only have 3 items in the feed
        feed_count = feed.count()
        self.assertEqual(feed_count, max_loves)

        # but we should fallback to the database
        feed_results = feed[:20]
        self.assertEqual(len(feed_results), 20)
Exemple #7
0
    def test_small_feed_instance(self):
        for desired_max_length in range(3, 5):
            feed = DatabaseFallbackLoveFeed(
                self.bogus_user.id, max_length=desired_max_length)
            feed.delete()

            # test the basic scenario if we have no data
            results = feed[:desired_max_length]
            results = feed[:desired_max_length]

            # this should come from redis, since its smaller than the desired max length
            self.assertEqual(feed.source, 'redis')
            self.assertEqual(len(results), desired_max_length)
            self.assertEqual(feed.max_length, desired_max_length)
            self.assertEqual(feed.count(), desired_max_length)

            # these will have to come from the db
            results = feed[:desired_max_length + 2]
            self.assertEqual(feed.source, 'db')
            results = feed[:desired_max_length + 2]
            self.assertEqual(feed.source, 'db')
Exemple #8
0
    def test_small_feed_instance(self):
        for desired_max_length in range(3, 5):
            feed = DatabaseFallbackLoveFeed(self.bogus_user.id,
                                            max_length=desired_max_length)
            feed.delete()

            # test the basic scenario if we have no data
            results = feed[:desired_max_length]
            results = feed[:desired_max_length]

            # this should come from redis, since its smaller than the desired max length
            self.assertEqual(feed.source, 'redis')
            self.assertEqual(len(results), desired_max_length)
            self.assertEqual(feed.max_length, desired_max_length)
            self.assertEqual(feed.count(), desired_max_length)

            # these will have to come from the db
            results = feed[:desired_max_length + 2]
            self.assertEqual(feed.source, 'db')
            results = feed[:desired_max_length + 2]
            self.assertEqual(feed.source, 'db')