def test_callRemote_traps_failure(self): class ExampleProxy: def not_ok(self, a, b, c=None): raise RuntimeError((c, b, a)) proxy = DeferredBlockingProxy(ExampleProxy()) d = proxy.callRemote('not_ok', 2, 3, c=8) error = self.assertRaises(RuntimeError, extract_result, d) self.assertEqual(str(error), str((8, 3, 2)))
def test_callRemote_calls_attribute(self): class ExampleProxy: def ok(self, a, b, c=None): return (c, b, a) proxy = DeferredBlockingProxy(ExampleProxy()) d = proxy.callRemote('ok', 2, 3, c=8) result = extract_result(d) self.assertEqual((8, 3, 2), result)
def get_lp_server(user_id, codehosting_endpoint_url=None, branch_url=None, seen_new_branch_hook=None, branch_transport=None): """Create a Launchpad server. :param user_id: A unique database ID of the user whose branches are being served. :param codehosting_endpoint_url: URL for the branch file system end-point. :param hosted_directory: Where the branches are uploaded to. :param mirror_directory: Where all Launchpad branches are mirrored. :param seen_new_branch_hook: :return: A `LaunchpadServer`. """ # Get the defaults from the config. if codehosting_endpoint_url is None: codehosting_endpoint_url = config.codehosting.codehosting_endpoint if branch_url is None: if branch_transport is None: branch_url = config.codehosting.mirrored_branches_root branch_transport = get_chrooted_transport(branch_url) else: if branch_transport is None: branch_transport = get_chrooted_transport(branch_url) else: raise AssertionError( "can't supply both branch_url and branch_transport!") codehosting_client = xmlrpclib.ServerProxy(codehosting_endpoint_url) lp_server = LaunchpadServer(DeferredBlockingProxy(codehosting_client), user_id, branch_transport, seen_new_branch_hook) return lp_server
def get_ro_server(): """Get a Launchpad internal server for scanning branches.""" proxy = xmlrpclib.ServerProxy(config.codehosting.codehosting_endpoint) codehosting_endpoint = DeferredBlockingProxy(proxy) branch_transport = get_readonly_transport( get_transport(config.codehosting.internal_branch_by_id_root)) return LaunchpadInternalServer('lp-internal:///', codehosting_endpoint, branch_transport)
def __init__(self): """Initialize the server. We register ourselves with the scheme lp-testing=${id(self)}:/// using an in-memory XML-RPC client and backed onto a LocalTransport. """ frontend = InMemoryFrontend() branchfs = frontend.getCodehostingEndpoint() branch = frontend.getLaunchpadObjectFactory().makeAnyBranch() self._branch_path = branch.unique_name # XXX: JonathanLange bug=276972 2008-10-07: This should back on to a # MemoryTransport, but a bug in Bazaar's implementation makes it # unreliable for tests that involve particular errors. LaunchpadInternalServer.__init__( self, 'lp-testing-%s:///' % id(self), DeferredBlockingProxy(branchfs), LocalTransport(local_path_to_url('.'))) self._chroot_servers = []
def get_rw_server(direct_database=False): """Get a server that can write to the Launchpad branch vfs. You can only call this usefully on the codehost -- the transport this server provides are backed onto file:/// URLs. :param direct_database: if True, use a server implementation that talks directly to the database. If False, the default, use a server implementation that talks to the internal XML-RPC server. """ transport = get_chrooted_transport( config.codehosting.mirrored_branches_root, mkdir=True) if direct_database: return DirectDatabaseLaunchpadServer('lp-internal:///', transport) else: proxy = xmlrpclib.ServerProxy(config.codehosting.codehosting_endpoint) codehosting_endpoint = DeferredBlockingProxy(proxy) return LaunchpadInternalServer('lp-internal:///', codehosting_endpoint, transport)