Exemplo n.º 1
0
 def test_set_delete(self):
     r = Client()
     r.delete("ll")
     r.sadd("ll", 42) == 1
     assert r.get("ll") == {42}
     assert r.delete("ll")
     assert r.get("ll") == None
Exemplo n.º 2
0
 def test_queue_delete(self):
     r = Client()
     r.delete("ll")
     r.rpush("ll", 42) == 1
     assert r.get("ll") == [42]
     assert r.delete("ll")
     assert r.get("ll") == None
Exemplo n.º 3
0
 def test_x(self):
     r1 = Client()
     r2 = Client()
     r3 = Client()
     assert r1.set("yo", 666) == True
     assert r2.get("yo") == 666
     assert "yo" in r3.keys()
Exemplo n.º 4
0
    def test_5(self):
        r1 = Client()
        assert r1.publish("newtoto",
                          "hello") == False  # nobody is subscribing that
        r2 = Client()
        assert r2.subscribe("newtoto") == True
        assert r1.publish("newtoto", "hello") == True
        assert r2.unsubscribe("newtoto") == True

        assert r2.get_event("newtoto") == None
        assert r1.publish("newtoto",
                          "hello") == False  # nobody is subscribing that
Exemplo n.º 5
0
    def test_cant_mutate_set(self):
        r = Client()
        r.set("jo", {42, 43})
        assert r.get("jo") == {42, 43}
        with self.assertRaises(Exception) as context:
            r.srem("jo", 42)  # jo is a real set, not a redys set

        with self.assertRaises(Exception) as context:
            r.sadd("jo", 44)  # jo is a real set, not a redys set
Exemplo n.º 6
0
    def test_try_queue_method_with_bad_type(self):
        r = Client()
        r.set("kiki", "hello")

        with self.assertRaises(Exception) as context:
            r.rpop("kiki")

        with self.assertRaises(Exception) as context:
            r.rpush("kiki", 42)

        assert r.get("kiki") == "hello"
Exemplo n.º 7
0
    def test_try_incdec_method_with_bad_type(self):
        r = Client()
        r.set("kiki", "hello")

        with self.assertRaises(Exception) as context:
            r.incr("kiki")
        with self.assertRaises(Exception) as context:
            r.decr("kiki")
Exemplo n.º 8
0
    def test_3(self):
        r = Client()

        assert r.subscribe("toto") == True
        assert r.publish("toto", 42) == True
        assert r.publish("toto", "hello") == True

        assert r.get_event("toto") == 42
        assert r.get_event("toto") == "hello"
        assert r.get_event("toto") == None
        assert r.publish("toto", 99) == True
        assert r.unsubscribe("toto")
Exemplo n.º 9
0
 def test_cache2(self):
     r = Client()
     r.setex("kiki", 0.05, 42)
     assert r.incr("kiki", 6) == 48
     assert r.get("kiki") == 48
     time.sleep(0.05)
     assert r.get("kiki") == None
Exemplo n.º 10
0
 def test_cache3(self):
     r = Client()
     r.setex("kiki", 0.05, 42)
     assert r.incr("kiki", 6) == 48
     assert "kiki" in r.keys()
     time.sleep(0.05)
     assert "kiki" not in r.keys()
Exemplo n.º 11
0
 def test_multi(self):
     r = Client()
     r.set("v1", 11)
     r.set("v2", 22)
     assert r.get("v1", "v3", "v2") == [11, None, 22]
     assert r.delete("v1", "v3", "v2") == True
     assert r.get("v1", "v3", "v2") == [None, None, None]
Exemplo n.º 12
0
    def test_0(self):
        with Client() as c:
            assert c.set("jo", 42) == True
            assert c.get("jo") == 42

            assert c.set("jo", [1, 2, 3]) == True
            assert c.get("jo") == [1, 2, 3]

            assert c.set("jo", (1, 2, 3)) == True
            assert c.get("jo") == (1, 2, 3)
Exemplo n.º 13
0
    def test_2(self):
        r = Client()
        assert r.set("kkk", "v") == True

        assert r.get("kkk") == "v"

        assert "kkk" in r.keys()

        assert r.delete("kkk") == True

        assert "kkk" not in r.keys()
Exemplo n.º 14
0
 def test_events_multi_clients(self):
     r1 = Client()
     r2 = Client()
     rp = Client()
     assert r1.subscribe("mychannel")
     assert r2.subscribe("mychannel")
     assert rp.publish("mychannel", "hello")
     assert r1.get_event("mychannel") == "hello"
     assert r1.unsubscribe("mychannel")
     assert r1.get_event("mychannel") == None
     assert r2.get_event("mychannel") == "hello"
Exemplo n.º 15
0
 def test_7(self):
     r1 = Client()
     assert r1.unsubscribe(
         "xxxxx") == False  # unsubscribe without subscribe it before ....
Exemplo n.º 16
0
 def test_6(self):
     r1 = Client()
     assert r1.get_event(
         "xxxxx") == None  # get without subscribe before ....
Exemplo n.º 17
0
 def test_ping(self):
     assert Client().ping() == "pong"
Exemplo n.º 18
0
    def test_4(self):
        r1 = Client()
        r2 = Client()

        assert r1.subscribe("toto") == True
        assert r2.publish("toto", 42) == True
        assert r2.publish("toto", "hello") == True

        assert r1.get_event("toto") == 42
        assert r1.get_event("toto") == "hello"
        assert r1.get_event("toto") == None
        assert r2.publish("toto", 99) == True
        assert r1.get_event("toto") == 99
        assert r1.get_event("toto") == None
        assert r1.unsubscribe("toto")
Exemplo n.º 19
0
 def test_queues(self):
     r = Client()
     r.delete("ll")
     assert r.rpush("ll", 42) == 1
     assert r.rpush("ll", 43) == 2
     assert r.lpush("ll", 41) == 3
     assert r.get("ll") == [41, 42, 43]
     assert r.rpop("ll") == 43
     assert r.lpop("ll") == 41
     assert r.get("ll") == [42]
     assert r.lpop("ll") == 42
     assert r.get("ll") == None
     assert r.lpop("ll") == None
     assert r.rpop("ll") == None
Exemplo n.º 20
0
 def test_1(self):
     c = Client()
     assert c.get("xxx") == None
Exemplo n.º 21
0
    def test_cant_mutate_queue(self):
        r = Client()
        r.set("jo", [42, 43])
        assert r.get("jo") == [42, 43]
        with self.assertRaises(Exception) as context:
            r.rpush("jo", 44)

        with self.assertRaises(Exception) as context:
            r.lpush("jo", 44)

        with self.assertRaises(Exception) as context:
            r.rpop("jo")

        with self.assertRaises(Exception) as context:
            l.rpop("jo")
Exemplo n.º 22
0
    def test_set_method(self):
        r = Client()
        r.delete("a_set")

        assert r.sadd("a_set", 42) == 1
        assert r.sadd("a_set", 43) == 2
        assert r.sadd("a_set", 42) == 2

        assert r.get("a_set") == set((43, 42))

        assert r.srem("a_set", 666) == 2  # 666 not in set, len is the same

        assert r.srem("a_set", 42) == 1
        assert r.srem("a_set", 42) == 1
        assert r.srem("a_set", 43) == 0

        with self.assertRaises(Exception) as context:
            r.srem("a_set", 43)  # the set is dead

        assert r.get("a_set") == None
Exemplo n.º 23
0
    def test_try_set_method_with_bad_type(self):
        r = Client()
        r.delete("a_int", "unknown")

        assert r.set("a_int", 42)
        with self.assertRaises(Exception) as context:
            r.sadd("a_int", 42)
        with self.assertRaises(Exception) as context:
            r.srem("a_int", 42)

        with self.assertRaises(Exception) as context:
            r.srem("unknown", 42)
Exemplo n.º 24
0
    def test_incdec(self):
        r = Client()
        r.delete("val")
        assert r.get("val") == None

        assert r.incr("val") == 1
        assert r.get("val") == 1

        assert r.incr("val") == 2
        assert r.get("val") == 2

        assert r.decr("val") == 1
        assert r.get("val") == 1

        r.delete("val")
        assert r.get("val") == None

        r.decr("val")
        assert r.get("val") == -1
Exemplo n.º 25
0
 def test_cache(self):
     r = Client()
     r.setex("kiki", 0.05, "hello")
     assert r.get("kiki") == "hello"
     time.sleep(0.05)
     assert r.get("kiki") == None
Exemplo n.º 26
0
 def test_cache4(self):
     r = Client()
     r.set("kiki", [1, 2, 3], 0.05)
     assert "kiki" in r.keys()
     time.sleep(0.05)
     assert "kiki" not in r.keys()