Example #1
0
 def test_dehydrated_activity(self):
     activity_object = Pin(id=1)
     activity = Activity(1, LoveVerb, activity_object)
     dehydrated = activity.get_dehydrated()
     self.assertTrue(isinstance(dehydrated, DehydratedActivity))
     self.assertEquals(dehydrated.serialization_id,
                       activity.serialization_id)
Example #2
0
 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()
Example #3
0
 def generate_aggregated_activities(self, diff=0):
     aggregator = RecentVerbAggregator()
     activities = []
     for x in range(1, 20 + diff):
         activity = Activity(x, LoveVerb, Pin(id=x))
         activities.append(activity)
     aggregated_activities = aggregator.aggregate(activities)
     return aggregated_activities
Example #4
0
 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 = {}
Example #5
0
 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
     ]
Example #6
0
    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()
Example #7
0
 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 = self.activity_class(
         1, LoveVerb, self.pin, 1, datetime.datetime.now(), {})
     activities = []
     for x in range(10):
         activity_time = datetime.datetime.now() + datetime.timedelta(
             hours=1)
         activity = self.activity_class(
             x, LoveVerb, self.pin, x, activity_time, dict(x=x))
         activities.append(activity)
     self.activities = activities
Example #8
0
 def test_aggregated_remove(self):
     activity_object = Pin(id=1)
     activities = []
     for x in range(1, 101):
         activity = Activity(x, LoveVerb, activity_object)
         activities.append(activity)
     aggregator = RecentVerbAggregator()
     aggregated_activities = aggregator.aggregate(activities)
     aggregated = aggregated_activities[0]
     for activity in activities:
         try:
             aggregated.remove(activity)
         except (ActivityNotFound, ValueError):
             pass
     self.assertEqual(len(aggregated.activities), 1)
     self.assertEqual(aggregated.activity_count, 72)
Example #9
0
    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
Example #10
0
    def test_aggregated_properties(self):
        activities = []
        for x in range(1, 101):
            activity_object = Pin(id=x)
            activity = Activity(x, LoveVerb, activity_object)
            activities.append(activity)
        aggregator = RecentVerbAggregator()
        aggregated_activities = aggregator.aggregate(activities)
        aggregated = aggregated_activities[0]

        self.assertEqual(aggregated.verbs, [LoveVerb])
        self.assertEqual(aggregated.verb, LoveVerb)
        self.assertEqual(aggregated.actor_count, 100)
        self.assertEqual(aggregated.minimized_activities, 85)
        self.assertEqual(aggregated.other_actor_count, 98)
        self.assertEqual(aggregated.activity_count, 100)
        self.assertEqual(aggregated.object_ids, range(86, 101))
        # the other ones should be dropped
        self.assertEqual(aggregated.actor_ids, range(86, 101))
        self.assertEqual(aggregated.is_seen(), False)
        self.assertEqual(aggregated.is_read(), False)
Example #11
0
 def test_serialization_type(self):
     activity_object = Pin(id=1)
     activity = Activity(1, LoveVerb, activity_object)
     assert isinstance(activity.serialization_id, (int, long, float))
Example #12
0
 def test_compare_apple_and_oranges(self):
     activity_object = Pin(id=1)
     activity = Activity(1, LoveVerb, activity_object)
     with self.assertRaises(ValueError):
         activity == activity_object
Example #13
0
 def test_contains(self):
     activity = Activity(1, LoveVerb, Pin(id=1))
     aggregated = AggregatedActivity(1, [activity])
     self.assertTrue(aggregated.contains(activity))
Example #14
0
 def test_duplicated_activities(self):
     activity = Activity(1, LoveVerb, Pin(id=1))
     aggregated = AggregatedActivity(1, [activity])
     with self.assertRaises(DuplicateActivityException):
         aggregated.append(activity)
Example #15
0
 def test_serialization_length(self):
     activity_object = Pin(id=1)
     activity = Activity(1, LoveVerb, activity_object)
     assert len(str(activity.serialization_id)) == 26
Example #16
0
 def test_serialization_overflow_check_role_id(self):
     activity_object = Pin(id=1)
     Verb = type('Overflow', (LoveVerb, ), {'id': 9999})
     activity = Activity(1, Verb, activity_object)
     with self.assertRaises(TypeError):
         activity.serialization_id
Example #17
0
 def test_serialization_overflow_check_object_id(self):
     activity_object = Pin(id=10**10)
     activity = Activity(1, LoveVerb, activity_object)
     with self.assertRaises(TypeError):
         activity.serialization_id
Example #18
0
 def test_compare_apple_and_oranges(self):
     activity = AggregatedActivity(1, [Activity(1, LoveVerb, Pin(id=1))])
     with self.assertRaises(ValueError):
         activity == Pin(id=1)
Example #19
0
 def test_contains_extraneous_object(self):
     activity = AggregatedActivity(1, [Activity(1, LoveVerb, Pin(id=1))])
     with self.assertRaises(ValueError):
         activity.contains(Pin(id=1))