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_set_get(self): """set/get""" ctx = Context(42) ctx._connection = ConnectionStub() yield ctx.set("foo", "bar") foo = yield ctx.get("foo") self.assertEquals(foo, "bar")
def test_delete(self): """La suppression doit fonctionner correctement""" ctx = Context(42) ctx._connection = ConnectionStub() yield ctx.set("foo", "bar") yield ctx.delete("foo") foo = yield ctx.get("foo") self.assertEquals(foo, None)
def test_set_unicode(self): """Set 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.assertFalse(isinstance(key, unicode), "Toutes les clés doivent être des str") self.assertEquals('vigilo%3A%C3%A9+%C3%A0+%C3%A8%3A42', key) d = ctx.set(u"é à è", "bar") d.addCallback(check) return d
def test_deleteshared_unicode(self): """Delete partagé sur le contexte (support d'unicode)""" ctx = Context(42) ctx._connection = MemcachedConnectionStub() def check(x): print repr(ctx._connection._cache.delete.call_args) key = ctx._connection._cache.delete.call_args[0][0] self.assertTrue( isinstance(key, str), "Toutes les clés doivent être des str, pas d'unicode") self.assertEquals('shared%3A%C3%A9+%C3%A0+%C3%A8', key) d = ctx.deleteShared(u"é à è") d.addCallback(check) return d
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 on_host_down(result, forwarder, database, idnt, ctx=None): # pylint: disable-msg=W0613 # W0613: Unused arguments 'forwarder', 'result' if ctx is None: # pour les tests unitaires ctx = Context(idnt) hostname = yield ctx.get("hostname") timestamp = yield ctx.get('timestamp') message = _("Host is down") services = yield get_all_services(hostname, database) LOGGER.info(_("Setting %d services to UNKNOWN"), len(services)) for svc in services: yield database.run( insert_state, { "host": hostname, "service": svc.servicename, "message": message, "timestamp": timestamp, "state": "UNKNOWN", "idsupitem": svc.idsupitem, } )
def test_context_specific(self): """ L'attribut classique est spécifique au contexte donc sa valeur n'est pas vue par les autres contextes. """ ctx = Context(42) ctx._connection = ConnectionStub() yield ctx.set("foo", "bar") ctx2 = Context(43) ctx2._connection = ConnectionStub() foo = yield ctx2.get("foo") self.assertEquals(foo, None)