Ejemplo n.º 1
0
def test_unsupported_method():
    redis = RedisSpy()
    subredis = SubRedis("prefix", redis)
    try:
        subredis.client_kill()
        assert False
    except NotSupportedError:
        pass
Ejemplo n.º 2
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"
Ejemplo n.º 3
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"
Ejemplo n.º 4
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
Ejemplo n.º 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()
Ejemplo n.º 6
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
Ejemplo n.º 7
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()
Ejemplo n.º 8
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"
Ejemplo n.º 9
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
Ejemplo n.º 10
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
Ejemplo n.º 11
0
def test_direct_proxy():
    redis = RedisSpy()
    subredis = SubRedis("prefix", redis)
    subredis.pipeline("blah")
    assert redis.lastCall == "pipeline"