示例#1
0
class BaseTest(unittest.TestCase):
    def setUp(self):
        self.a = ActivityFeed(redis='redis://:@localhost:6379/15')
        self._empty()

    def _empty(self):
        a = self.a
        keys = a.redis.keys('{}*'.format(a.namespace))

        if keys:
            a.redis.delete(*keys)

    def add_items_to_feed(self, user_id, items_to_add=5, aggregate=None):
        """Helper method to add items to a given feed.

        :param items_to_add: [int] Number of items to add to the feed.
        """
        if aggregate is None:
            aggregate = self.a.aggregate

        now = timestamp_utcnow()

        for i in range(1, items_to_add + 1):
            self.a.update_item(user_id, i, now, aggregate)
            now += 5
示例#2
0
class BaseTest(unittest.TestCase):
    def setUp(self):
        self.a = ActivityFeed(redis="redis://:@localhost:6379/15")
        self._empty()

    def _empty(self):
        a = self.a
        keys = a.redis.keys("{}*".format(a.namespace))

        if keys:
            a.redis.delete(*keys)

    def add_items_to_feed(self, user_id, items_to_add=5, aggregate=None):
        """Helper method to add items to a given feed.

        :param items_to_add: [int] Number of items to add to the feed.
        """
        if aggregate is None:
            aggregate = self.a.aggregate

        now = timestamp_utcnow()

        for i in range(1, items_to_add + 1):
            self.a.update_item(user_id, i, now, aggregate)
            now += 5
示例#3
0
    def test_feederboard_for(self):
        'should create a leaderboard using an existing Redis connection'
        a = ActivityFeed()
        feederboard_david = a.feederboard_for('david')
        feederboard_person = a.feederboard_for('person')

        self.assertEqual(feederboard_david is None, False)
        self.assertEqual(feederboard_person is None, False)
示例#4
0
    def test_feederboard_for(self):
        'should create a leaderboard using an existing Redis connection'
        a = ActivityFeed()
        feederboard_david = a.feederboard_for('david')
        feederboard_person = a.feederboard_for('person')

        self.assertEqual(feederboard_david is None, False)
        self.assertEqual(feederboard_person is None, False)
示例#5
0
def example_setup():
    global a
    a = ActivityFeed(redis='redis://:@localhost:6379/15',
                     items_loader=items_loader,
                     aggregate=True)

    _empty(a)

    #now = timestamp_utcnow()

    #for i in range(1, 1200, 2):
    #    create_item(a, 'foo', i, now)
    #    now += 5
    #    create_item(a, 'bar', i+1, now)
    #    a.aggregate_item('foo', i+1, now)
    #    now += 5

    return a
示例#6
0
 def test_key(self):
     'should return the correct key for the non-aggregate feed'
     a = ActivityFeed()
     self.assertEquals(a.feed_key('david'), 'activity_feed:david')
示例#7
0
 def test_key_aggregate(self):
     'should return the correct key for an aggregate feed'
     a = ActivityFeed()
     self.assertEqual(a.feed_key('david', True), 'activity_feed:aggregate:david')
示例#8
0
 def setUp(self):
     self.a = ActivityFeed(redis='redis://:@localhost:6379/15')
     self._empty()
示例#9
0
 def setUp(self):
     self.a = ActivityFeed(redis="redis://:@localhost:6379/15")
     self._empty()
示例#10
0
 def test_key(self):
     'should return the correct key for the non-aggregate feed'
     a = ActivityFeed()
     self.assertEquals(a.feed_key('david'), 'activity_feed:david')
示例#11
0
 def test_key_aggregate(self):
     'should return the correct key for an aggregate feed'
     a = ActivityFeed()
     self.assertEqual(a.feed_key('david', True),
                      'activity_feed:aggregate:david')