コード例 #1
0
ファイル: test_redis_models.py プロジェクト: eiritana/canvas
class TestRedisHash(CanvasTestCase):
    def after_setUp(self):
        redis.delete('rh_key')
        self.rh = RedisHash('rh_key')

    def test_hincrby_ifsufficient_none(self):
        result = self.rh.hincrby_ifsufficient('balance', -5)
        self.assertEqual(result['success'], False)
        self.assertEqual(result['remaining'], 0)

    def test_hincrby_ifsufficient_enough(self):
        self.rh.hset('balance', 8)
        result = self.rh.hincrby_ifsufficient('balance', -5)
        self.assertEqual(result['success'], True)
        self.assertEqual(result['remaining'], 3)

    def test_hincrby_ifsufficient_justenough(self):
        self.rh.hset('balance', 5)
        result = self.rh.hincrby_ifsufficient('balance', -5)
        self.assertEqual(result['success'], True)
        self.assertEqual(result['remaining'], 0)

    def test_hincrby_ifsufficient_notquiteenough(self):
        self.rh.hset('balance', 4)
        result = self.rh.hincrby_ifsufficient('balance', -5)
        self.assertEqual(result['success'], False)
        self.assertEqual(result['remaining'], 4)
コード例 #2
0
class TestRedisHash(CanvasTestCase):
    def after_setUp(self):
        redis.delete('rh_key')
        self.rh = RedisHash('rh_key')

    def test_hincrby_ifsufficient_none(self):
        result = self.rh.hincrby_ifsufficient('balance', -5)
        self.assertEqual(result['success'], False)
        self.assertEqual(result['remaining'], 0)

    def test_hincrby_ifsufficient_enough(self):
        self.rh.hset('balance', 8)
        result = self.rh.hincrby_ifsufficient('balance', -5)
        self.assertEqual(result['success'], True)
        self.assertEqual(result['remaining'], 3)

    def test_hincrby_ifsufficient_justenough(self):
        self.rh.hset('balance', 5)
        result = self.rh.hincrby_ifsufficient('balance', -5)
        self.assertEqual(result['success'], True)
        self.assertEqual(result['remaining'], 0)

    def test_hincrby_ifsufficient_notquiteenough(self):
        self.rh.hset('balance', 4)
        result = self.rh.hincrby_ifsufficient('balance', -5)
        self.assertEqual(result['success'], False)
        self.assertEqual(result['remaining'], 4)
コード例 #3
0
class _CompressedFiles(object):
    hashes = {
        'css': RedisHash('compressed:css'),
        'js': RedisHash('compressed:js'),
    }

    def set(self, type, name, path):
        self.hashes[type].hset(name, path)

    def get(self, type, name):
        return self.hashes[type].hget(name)
コード例 #4
0
ファイル: stickers.py プロジェクト: StetHD/canvas-2
def get_actions(user):
    """ Returns a list of stickers. """
    actions = actions_base[:]
    if user.is_authenticated():
        if user.is_staff:
            actions += actions_staff
        if user.userinfo.details()['moderatable']:
            actions += actions_group_mod
        # Grab stickers that are lab options
        if labs_actions:
            kv = user.redis.user_kv.hgetall()
            for action in labs_actions:
                if RedisHash.read_bool(kv, "labs:"+action.name):
                    actions.append(action)
    return actions
コード例 #5
0
def get_actions(user):
    """ Returns a list of stickers. """
    actions = actions_base[:]
    if user.is_authenticated():
        if user.is_staff:
            actions += actions_staff
        if user.userinfo.details()['moderatable']:
            actions += actions_group_mod
        # Grab stickers that are lab options
        if labs_actions:
            kv = user.redis.user_kv.hgetall()
            for action in labs_actions:
                if RedisHash.read_bool(kv, "labs:" + action.name):
                    actions.append(action)
    return actions
コード例 #6
0
ファイル: experiments.py プロジェクト: eiritana/canvas
class UserExperimentsBackend(object):
    """ A wrapper around a Redis hash to store experiments for an existing user. """
    logged_in = True

    def __init__(self, user_id, staff):
        self._user_id = user_id
        self.staff = staff
        self.key = user_id

    def get_experiments(self):
        return self.user_experiments.hgetall()

    def add(self, experiment, branch):
        self.user_experiments.hset(experiment.name, branch.name)
        branch.users.sadd(self._user_id)

    user_experiments = property(lambda self: RedisHash('user:%s:experiments' % self._user_id))
コード例 #7
0
 def after_setUp(self):
     redis.delete('rh_key')
     self.rh = RedisHash('rh_key')
コード例 #8
0
ファイル: test_redis_models.py プロジェクト: eiritana/canvas
 def after_setUp(self):
     redis.delete('rh_key')
     self.rh = RedisHash('rh_key')