def test_shared_set_get(self): """set/get d'un attribut partagé""" ctx = Context(42) ctx._connection = ConnectionStub() yield ctx.setShared("foo", "bar") foo = yield ctx.getShared("foo") self.assertEquals(foo, "bar")
def test_shared_visibility(self): """Visibilité des attributs partagés""" ctx = Context(42) ctx._connection = ConnectionStub() yield ctx.setShared("foo", "bar") ctx2 = Context(43) ctx2._connection = ConnectionStub() foo = yield ctx2.getShared("foo") self.assertEquals(foo, "bar") yield ctx.deleteShared("foo") foo = yield ctx2.getShared("foo") self.assertEquals(foo, None)
def test_setShared_unicode(self): """Set partagé sur le contexte (support d'unicode)""" ctx = Context(42) ctx._connection = MemcachedConnectionStub() def check(x): print repr(ctx._connection._cache.set.call_args) key = ctx._connection._cache.set.call_args[0][0] self.assertTrue( isinstance(key, str), "Toutes les clés doivent être des str") self.assertEquals('shared%3A%C3%A9+%C3%A0+%C3%A8', key) d = ctx.setShared(u"é à è", "bar") d.addCallback(check) return d