Esempio n. 1
0
 def test_limit_actually_limits(self):
     collection = BsonCollection(
         os.path.dirname(os.path.realpath(__file__)) + '/' +
         config['bson']['valid'])
     collection.get_iterator()
     count = len(
         list(tweet for tweet in collection.set_limit(5).get_iterator()))
     self.assertEqual(5, count)
Esempio n. 2
0
	def test_collection_filters_custom_filter_filters_something(self):
		collection = BsonCollection(os.path.dirname(os.path.realpath(__file__)) +'/'+ config['bson']['valid'])
		long_len = len(list(collection.get_iterator()))
		def is_tweet_a_retweet(tweet):
			if 'retweeted' in tweet and tweet['retweeted']:
				return True
			else:
				return False
		collection.set_custom_filter(is_tweet_a_retweet)
		shorter_len = len(list(collection.get_iterator()))

		#there should be fewer retweets than all tweets.
		self.assertTrue(long_len > shorter_len)
Esempio n. 3
0
    def test_collection_filters_custom_filter_properly_applies_filter(self):
        collectionone = BsonCollection(
            os.path.dirname(os.path.realpath(__file__)) + '/' +
            config['bson']['valid'])
        full_collection_len = len(list(collectionone.get_iterator()))

        def is_tweet_a_retweet(tweet):
            if 'retweeted' in tweet and tweet['retweeted']:
                return True
            else:
                return False

        num_retweets = len(
            list(
                collectionone.set_custom_filter(
                    is_tweet_a_retweet).get_iterator()))

        collectiontwo = BsonCollection(
            os.path.dirname(os.path.realpath(__file__)) + '/' +
            config['bson']['valid'])

        def is_not_a_retweet(tweet):
            if 'retweeted' in tweet and tweet['retweeted']:
                return False
            else:
                return True

        num_non_retweets = len(
            list(
                collectiontwo.set_custom_filter(
                    is_not_a_retweet).get_iterator()))

        #the numbes of retweets and non retweets should add up to the whole collection
        self.assertEqual(num_retweets + num_non_retweets, full_collection_len)
Esempio n. 4
0
    def test_collection_filters_custom_filter_filters_something(self):
        collection = BsonCollection(
            os.path.dirname(os.path.realpath(__file__)) + '/' +
            config['bson']['valid'])
        long_len = len(list(collection.get_iterator()))

        def is_tweet_a_retweet(tweet):
            if 'retweeted' in tweet and tweet['retweeted']:
                return True
            else:
                return False

        collection.set_custom_filter(is_tweet_a_retweet)
        shorter_len = len(list(collection.get_iterator()))

        #there should be fewer retweets than all tweets.
        self.assertTrue(long_len > shorter_len)
	def test_bson_collection_custom_filter_filters(self):
		collectionone = BsonCollection(os.path.dirname(os.path.realpath(__file__)) +'/'+ config['bson']['valid'])
		full_collection_len = len(list(collectionone.get_iterator()))
		def is_tweet_a_retweet(tweet):
			if 'retweeted' in tweet and tweet['retweeted']:
				return True
			else:
				return False
		num_retweets = len(list(collectionone.set_custom_filter(is_tweet_a_retweet).get_iterator()))

		collectiontwo = BsonCollection(os.path.dirname(os.path.realpath(__file__)) +'/'+ config['bson']['valid'])
		def is_not_a_retweet(tweet):
			if 'retweeted' in tweet and tweet['retweeted']:
				return False
			else:
				return True
		num_non_retweets = len(list(collectiontwo.set_custom_filter(is_not_a_retweet).get_iterator()))
		
		#the numbes of retweets and non retweets should add up to the whole collection
		self.assertEqual(num_retweets + num_non_retweets, full_collection_len)
Esempio n. 6
0
	def test_limit_actually_limits(self):
		collection = BsonCollection(os.path.dirname(os.path.realpath(__file__)) +'/'+ config['bson']['valid'])
		collection.get_iterator()
		count = len(list(tweet for tweet in collection.set_limit(5).get_iterator()))
		self.assertEqual(5, count)
Esempio n. 7
0
	def test_iterator_returns_tweets(self):
		collection = BsonCollection(os.path.dirname(os.path.realpath(__file__)) +'/'+ config['bson']['valid'])
		self.assertTrue(len(list(collection.get_iterator())) > 0)