def test_class_service(self): class DummyService(object): def __init__(self, request): self.request = request def say_hello(self): return "Hello World" service = Service("classservice") service.add_method("sayHello", "say_hello", klass=DummyService) self.assertTrue(service.methods.get("sayHello")) result = service.execute("sayHello", mock.MagicMock()) self.assertEqual(result, "Hello World")
def add_resource(klass, name): """Register a resource class. :param klass: the class to register the service :param name: name of the service """ service = Service(name) for name in dir(klass): if name.startswith('__'): continue meth = getattr(klass, name) rcpmethod = getattr(meth, '__rpcmethod__', None) if rcpmethod is None: continue service.add_method(rcpmethod, name, klass=klass) return klass