def setUp(self): self.user_id = 42 self.test_feed = self.feed_cls(self.user_id) self.activity = FakeActivity( 1, LoveVerb, 1, 1, datetime.datetime.now(), {}) activities = [] base_time = datetime.datetime.now() - datetime.timedelta(days=10) for x in range(1, 10): activity_time = base_time + datetime.timedelta( hours=x) activity = FakeActivity( x, LoveVerb, 1, x, activity_time, dict(x=x)) activities.append(activity) for x in range(20, 30): activity_time = base_time + datetime.timedelta( hours=x) activity = FakeActivity( x, AddVerb, 1, x, activity_time, dict(x=x)) activities.append(activity) self.activities = activities aggregator = self.test_feed.get_aggregator() self.aggregated_activities = aggregator.aggregate(activities) self.aggregated = self.aggregated_activities[0] if self.__class__ != TestAggregatedFeed: self.test_feed.delete()
def setUp(self): self.user_id = 42 self.test_feed = self.feed_cls(self.user_id) self.pin = Pin(id=1, created_at=datetime.datetime.now() - datetime.timedelta(hours=1)) self.activity = FakeActivity(1, LoveVerb, self.pin, 1, datetime.datetime.now(), {}) activities = [] for x in range(10): activity_time = datetime.datetime.now() + datetime.timedelta( hours=1) activity = FakeActivity(x, LoveVerb, self.pin, x, activity_time, dict(x=x)) activities.append(activity) self.activities = activities
def setUp(self): self.feedly = self.manager_class() self.actor_id = 42 self.pin = Pin( id=1, created_at=datetime.datetime.now() - datetime.timedelta(hours=1)) self.activity = FakeActivity( self.actor_id, LoveVerb, self.pin, 1, datetime.datetime.now(), {}) self.feedly.flush()
def setUp(self): self.pin = Pin(id=1, created_at=datetime.datetime.now() - datetime.timedelta(hours=1)) self.storage = self.storage_cls(**self.storage_options) self.activity = FakeActivity(1, PinVerb, self.pin, 1, datetime.datetime.now(), {}) self.args = () self.kwargs = {}
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 = {}
def _build_activity_list(self, ids_list): now = datetime.datetime.now() pins = [ Pin(id=i, created_at=now + datetime.timedelta(hours=i)) for i in ids_list ] pins_ids = zip(pins, ids_list) return [ FakeActivity(i, PinVerb, pin, i, now + datetime.timedelta(hours=i), {'i': i}) for id, pin in pins_ids ]
def test_add_many_and_trim(self): activities = [] for i in range(50): activity = FakeActivity(i, LoveVerb, i, i, datetime.datetime.now(), {}) activities.append(activity) self.test_feed.insert_activities(activities) self.test_feed.add_many(activities) self.assertEqual(self.test_feed.count(), 50) self.test_feed.trim(10) self.assertEqual(self.test_feed.count(), 10)
def setUp(self): id_seq = range(42, 999) if self.aggregator_class is None: return self.user_id = 42 self.activity = FakeActivity(1, LoveVerb, 1, 1, datetime.datetime.now(), {}) self.activities = [] for x in range(2, 12): activity_time = datetime.datetime.now() find = x > 5 activity = FakeActivity(x, LoveVerb, id_seq.pop(), x, activity_time, dict(find=find)) self.activities.append(activity) self.add_activities = [] for x in range(13, 38): activity_time = datetime.datetime.now() + datetime.timedelta( seconds=x) activity = FakeActivity(x, AddVerb, id_seq.pop(), x, activity_time, dict(x=x)) self.add_activities.append(activity) self.aggregator = self.aggregator_class()
def setUp(self): self.feedly = self.manager_class() self.actor_id = 42 self.pin = Pin(id=1, created_at=datetime.datetime.now() - datetime.timedelta(hours=1)) self.activity = FakeActivity(self.actor_id, LoveVerb, self.pin, 1, datetime.datetime.now(), {}) if self.__class__ != BaseFeedlyTest: for user_id in range(1, 4) + [17, 42, 44]: self.feedly.get_user_feed(user_id).delete() for feed in self.feedly.get_feeds(user_id).values(): feed.delete()
def setUp(self): if self.aggregator_class is None: return self.user_id = 42 self.activity = FakeActivity(1, LoveVerb, 1, 1, datetime.datetime.now(), {}) activities = [] for x in range(1, 11): activity_time = datetime.datetime.now() find = x > 5 activity = FakeActivity(x, LoveVerb, 1, x, activity_time, dict(find=find)) activities.append(activity) add_activities = [] for x in range(1, 26): activity_time = datetime.datetime.now() + datetime.timedelta( seconds=4) activity = FakeActivity(x, AddVerb, 1, x, activity_time, dict(x=x)) add_activities.append(activity) self.activities = activities self.add_activities = add_activities self.aggregator = self.aggregator_class()
def test_add_many_and_trim(self): activities = [] choices = [LoveVerb, AddVerb] for i in range(1, 50): verb = choices[i % 2] activity = FakeActivity( i, verb, i, i, datetime.datetime.now() - datetime.timedelta(seconds=i)) activities.append(activity) self.test_feed.insert_activities(activities) self.test_feed.add_many(activities) # now test the trim self.assertEqual(self.test_feed.count(), 2) self.test_feed.trim(1) self.assertEqual(self.test_feed.count(), 1)
def test_feed_slice(self): activity_dict = {} for i in range(10): activity = FakeActivity(i, LoveVerb, i, i, time=datetime.datetime.now() - datetime.timedelta(seconds=i)) activity_dict[i] = activity self.test_feed.insert_activities(activity_dict.values()) self.test_feed.add_many(activity_dict.values()) results = self.test_feed[:] self.assertEqual(len(results), self.test_feed.count())
def prepare_filter(self): if not self.test_feed.filtering_supported: return # setup the data activity_dict = {} for i in range(10): activity = FakeActivity(i, LoveVerb, i, i, time=datetime.datetime.now() - datetime.timedelta(seconds=i)) activity_dict[i] = activity self.test_feed.insert_activities(activity_dict.values()) self.test_feed.add_many(activity_dict.values())
def setup_filter(self): if not self.test_feed.filtering_supported: self.skipTest('%s does not support filtering' % self.test_feed.__class__.__name__) activities = [] for i in range(10): activities.append( FakeActivity(i, LoveVerb, i, i, time=datetime.datetime.now() - datetime.timedelta(seconds=i))) self.test_feed.insert_activities(activities) self.test_feed.add_many(activities) assert len(self.test_feed[:]) == 10
def test_feed_indexof_large(self): assert self.test_feed.count() == 0 activity_dict = {} for i in range(150): moment = datetime.datetime.now() - datetime.timedelta(seconds=i) activity = FakeActivity(i, LoveVerb, i, i, time=moment) activity_dict[i] = activity self.test_feed.insert_activities(activity_dict.values()) self.test_feed.add_many(activity_dict.values()) # give cassandra a moment time.sleep(0.1) activity = activity_dict[110] index_of = self.test_feed.index_of(activity.serialization_id) self.assertEqual(index_of, 110)
def test_feed_timestamp_order(self): activities = [] deltas = [1, 2, 9, 8, 11, 10, 5, 16, 14, 50] for i in range(10): activity = FakeActivity(i, LoveVerb, i, i, time=datetime.datetime.now() - datetime.timedelta(seconds=deltas.pop())) activities.append(activity) self.feed_cls.insert_activity(activity) self.test_feed.add_many(activities) self._check_order(self.test_feed[:10]) self._check_order(self.test_feed[1:9]) self._check_order(self.test_feed[5:])
def test_large_remove_activity(self): # first built a large feed self.test_feed.max_length = 3600 activities = [] choices = [LoveVerb, AddVerb] for i in range(1, 3600): verb = choices[i % 2] activity = FakeActivity( i, verb, i, i, datetime.datetime.now() - datetime.timedelta(days=i)) activities.append(activity) self.test_feed.insert_activities(activities) self.test_feed.add_many(activities) to_remove = activities[200:700] self.test_feed.remove_many(to_remove)
def test_follow_unfollow_user(self): target_user_id = 17 target2_user_id = 44 follower_user_id = 42 control_pin = Pin(id=2, created_at=datetime.datetime.now() - datetime.timedelta(hours=1)) control_activity = FakeActivity(target_user_id, LoveVerb, control_pin, 2, datetime.datetime.now(), {}) with patch.object(self.feedly, 'get_user_follower_ids', return_value=[]) as get_user_follower_ids: self.feedly.add_user_activity(target2_user_id, control_activity) self.feedly.add_user_activity(target_user_id, self.activity) get_user_follower_ids.assert_called_with(user_id=target_user_id) # checks user feed is empty for f in self.feedly.get_feeds(follower_user_id).values(): self.assertEqual(f.count(), 0) self.feedly.follow_user(follower_user_id, target2_user_id) # make sure one activity was pushed for f in self.feedly.get_feeds(follower_user_id).values(): self.assertEqual(f.count(), 1) self.feedly.follow_user(follower_user_id, target_user_id) # make sure another one activity was pushed for f in self.feedly.get_feeds(follower_user_id).values(): self.assertEqual(f.count(), 2) self.feedly.unfollow_user(follower_user_id, target_user_id, async=False) # make sure only one activity was removed for f in self.feedly.get_feeds(follower_user_id).values(): self.assertEqual(f.count(), 1) activity = f[:][0] assert activity.object_id == self.pin.id
def test_large_remove_activity(self): # first built a large feed self.test_feed.max_length = 3600 activities = [] choices = [LoveVerb, AddVerb] for i in range(1, 3600): verb = choices[i % 2] activity = FakeActivity( i, verb, i, i, datetime.datetime.now() - datetime.timedelta(days=i)) activities.append(activity) self.test_feed.insert_activities(activities) self.test_feed.add_many(activities) to_remove = activities[200:700] remove_count = len(to_remove) feed_count = self.test_feed.count() t = timer() self.test_feed.remove_many(to_remove) msg_format = 'removing %s items from a feed of %s took %s seconds' print msg_format % (remove_count, feed_count, t.next())