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)
def test_set_custom_filter_is_not_double_set(self): collection = BsonCollection(os.path.dirname(os.path.realpath(__file__)) +'/'+ config['bson']['valid']) 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) self.assertFalse(len(collection.custom_filters) > 1)
def test_set_custom_filter_is_not_double_set(self): collection = BsonCollection( os.path.dirname(os.path.realpath(__file__)) + '/' + config['bson']['valid']) 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) self.assertFalse(len(collection.custom_filters) > 1)
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_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)