def test_intersect_leaderboards(self): foo = lb.Leaderboard('foo') bar = lb.Leaderboard('bar') foo.rank_member('foo_1', 1) foo.rank_member('foo_2', 2) foo.rank_member('bar_3', 6) bar.rank_member('bar_1', 3) bar.rank_member('foo_1', 4) bar.rank_member('bar_3', 5) # FIXME: add a constant for available aggregates num_foobar_keys = foo.intersect_leaderboards('foobar', ['bar'], aggregate="max") self.assertEqual(2, num_foobar_keys) foobar = lb.Leaderboard('foobar') self.assertEqual(2, foobar.total_members()) first_leader_in_foobar = foobar.leaders(1)[0] self.assertEqual(1, first_leader_in_foobar['rank']) self.assertEqual('bar_3', first_leader_in_foobar['member']) self.assertEqual(6, first_leader_in_foobar['score']) lb.teardown()
def test_merge_leaderboards(self): foo = lb.Leaderboard('foo') bar = lb.Leaderboard('bar') foo.rank_member('foo_1', 1) foo.rank_member('foo_2', 2) bar.rank_member('bar_1', 3) bar.rank_member('bar_2', 4) bar.rank_member('bar_3', 5) num_foobar_keys = foo.merge_leaderboards('foobar', ['bar']) self.assertEqual(5, num_foobar_keys) foobar = lb.Leaderboard('foobar') self.assertEqual(5, foobar.total_members()) first_leader_in_foobar = foobar.leaders(1)[0] self.assertEqual(1, first_leader_in_foobar['rank']) self.assertEqual('bar_3', first_leader_in_foobar['member']) self.assertEqual(5, first_leader_in_foobar['score']) lb.teardown()
def test_will_automatically_reconnect_after_a_disconnect(self): self.assertEqual(0, self.leaderboard.total_members()) self._rank_members_in_leaderboard(5) self.assertEqual(5, self.leaderboard.total_members()) lb.teardown() self.assertEqual(5, self.leaderboard.total_members())
def test_disconnect(self): # FIXME: what is assert nil really doing in ruby? lb.teardown()
def tearDown(self): self.conn.flushdb() lb.teardown() self.conn = None