def testOperationEvents(self): res = {"value": False} def callback(*args, **kwargs): res["value"] = True URL = "wave://[email protected]/test" evts = operation.Events("*****@*****.**", callback) # Create an operation for it's event. NS = opdev.OperationNS("pyofwave.info/test") @NS def op(event, *args, **kwargs): pass # Test that event isn't triggered before register operation.performOperation(evts, E.op(href=URL)) self.assertFalse(res["value"]) # Trigger event evts.register(URL, "{pyofwave.info/test}op") operation.performOperation(evts, E.op(href=URL)) self.assertTrue(res["value"]) # test different URL res["value"] = False operation.performOperation(evts, E.op(href="pyofwave.info/Firefly")) self.assertFalse(res["value"]) # Unregister res["value"] = False evts.unregister(URL, "{pyofwave.info/test}op") operation.performOperation(evts, E.op(href=URL)) self.assertFalse(res["value"])
def call(self): """Calls the method specified from the parsed request.""" err = None response = {} if self._mmethod: try: response = performOperation(self.transport.getPeer(), self._mmethod, self._mkwargs) self.sendResponse(self._mname, "RESPONSE.response", response) except (OperationError, err): self.sendError(self._mname, err) self._mname = "" self._mmethod = "" self._mkwargs = {}
def testEventRegisty(self): # Define a test context res = {"value": "FOO"} # Define a function used as event callback that will modify the context def misc(*args, **kwargs): res["value"] = "BAR" url = "wave://[email protected]/test" user = "******" event_registry = operation.EventRegisty(user=user, callback=misc) self.assertEqual(event_registry.user, user) # Create an operation for it's event. NS = opdev.OperationNS(ns) @NS def op(event, *args, **kwargs): pass # Test that event isn't triggered before register operation.performOperation(event_registry, self.E.op(href=url)) self.assertEqual(res["value"], "FOO") # Trigger event event_registry.register(url, "{%s}op" % ns) operation.performOperation(event_registry, self.E.op(href=url)) self.assertEqual(res["value"], "BAR") # test different URL res["value"] = "FOOBAR" operation.performOperation(event_registry, self.E.op(href="pyofwave.info/Firefly")) self.assertEqual(res["value"], "FOOBAR") # Unregister one event res["value"] = "BARFOO" event_registry.unregister(url, "{%s}op" % ns) operation.performOperation(event_registry, self.E.op(href=url)) self.assertEqual(res["value"], "BARFOO") # Unregister all events event_registry.register(url, "{%s}op1" % ns) event_registry.register(url, "{%s}op2" % ns) event_registry.unregister(url, "*")
def testEventRegisty(self): # Define a test context res = {"value": "FOO"} # Define a function used as event callback that will modify the context def misc(*args, **kwargs): res["value"] = "BAR" url = "wave://[email protected]/test" user="******" event_registry = operation.EventRegisty(user=user, callback=misc) self.assertEqual(event_registry.user, user) # Create an operation for it's event. NS = opdev.OperationNS(ns) @NS def op(event, *args, **kwargs): pass # Test that event isn't triggered before register operation.performOperation(event_registry, self.E.op(href=url)) self.assertEqual(res["value"],"FOO") # Trigger event event_registry.register(url, "{%s}op" % ns) operation.performOperation(event_registry, self.E.op(href=url)) self.assertEqual(res["value"], "BAR") # test different URL res["value"] = "FOOBAR" operation.performOperation(event_registry, self.E.op(href="pyofwave.info/Firefly")) self.assertEqual(res["value"], "FOOBAR") # Unregister one event res["value"] = "BARFOO" event_registry.unregister(url, "{%s}op" % ns) operation.performOperation(event_registry, self.E.op(href=url)) self.assertEqual(res["value"], "BARFOO") # Unregister all events event_registry.register(url, "{%s}op1" % ns) event_registry.register(url, "{%s}op2" % ns) event_registry.unregister(url, "*")
def testPerformOperation(self): res = operation.performOperation(None, E.op("test", E.tag(), "hello", action="test")) self.assertEqual(res.text, "success") self.assertEqual(res.get("status"), "400")