示例#1
0
def test_unsupported_method():
    redis = RedisSpy()
    subredis = SubRedis("prefix", redis)
    try:
        subredis.client_kill()
        assert False
    except NotSupportedError:
        pass
示例#2
0
def test_flushdb():
    subredis = SubRedis("prefix", r)
    r.set("unrelated", "unrelated")
    subredis.set("foo", "bar")
    subredis.set("baz", "bar")
    subredis.set("cats", "bar")
    subredis.flushdb()
    keys = subredis.keys()
    assert len(keys) == 0
示例#3
0
def test_set_get():
    subredis = SubRedis("prefix", r)
    r.set("unrelated", "unrelated")
    subredis.set("foo", "bar")
    subredis["baz"] = "snaz"
    assert subredis["foo"] == b"bar"
    assert subredis.get("foo") == b"bar"
    assert subredis["baz"] == b"snaz"
    assert subredis.get("baz") == b"snaz"
示例#4
0
def test_prefix_wrap_method():
    """ Test that the prefix is appended to methods that
        take a key as the first argument"""
    redis = RedisSpy()
    subredis = SubRedis("prefix", redis)
    redis.addSpy("hget")
    subredis.hget("foo")
    assert redis.lastCall == "hget"
    assert redis.lastArgs[0] == "prefix_foo"
示例#5
0
def test_get_from_pipeline():
    subredis = SubRedis("prefix", r)
    subredis.set("foo", "bar")
    subredis.set("shaz", "snaz")
    pipeline = subredis.pipeline()
    pipeline.get("foo")
    pipeline.get("shaz")
    result = pipeline.execute()
    result = [x.decode('utf-8') for x in result]
    assert result == ["bar", "snaz"]
    subredis.flushdb()
示例#6
0
def test_keys():
    subredis = SubRedis("prefix", r)
    r.set("unrelated", "unrelated")
    subredis.set("foo", "bar")
    subredis.set("baz", "bar")
    subredis.set("cats", "bar")
    keys = subredis.keys()
    keys = [x.decode('utf-8') for x in keys]
    assert "foo" in keys
    assert "baz" in keys
    assert "cats" in keys
    print(repr(keys))
    assert len(keys) == 3
示例#7
0
def test_direct_proxy():
    redis = RedisSpy()
    subredis = SubRedis("prefix", redis)
    subredis.pipeline("blah")
    assert redis.lastCall == "pipeline"