def make_factory(self, rpc_service=None): listener = FakePostgresListenerService() factory = WebSocketFactory(listener) if rpc_service is None: rpc_service = MagicMock() self.patch(services, "getServiceNamed").return_value = rpc_service return factory
def __init__(self, endpoint, listener, status_worker): self.site = OverlaySite(StartPage(), logFormatter=reducedWebLogFormatter) self.site.requestFactory = CleanPathRequest super(WebApplicationService, self).__init__(endpoint, self.site) self.websocket = WebSocketFactory(listener) self.threadpool = ThreadPoolLimiter(reactor.threadpoolForDatabase, concurrency.webapp) self.status_worker = status_worker
def make_protocol(self, patch_authenticate=True, transport_uri=''): listener = FakePostgresListenerService() factory = WebSocketFactory(listener) self.patch(factory, "registerRPCEvents") self.patch(factory, "unregisterRPCEvents") factory.startFactory() self.addCleanup(factory.stopFactory) protocol = factory.buildProtocol(None) protocol.transport = MagicMock() protocol.transport.cookies = b"" protocol.transport.uri = transport_uri if patch_authenticate: self.patch(protocol, "authenticate") return protocol, factory
def __init__(self, port, listener, status_worker): self.port = port self.starting = False # Start with an empty `Resource`, `installApplication` will configure # the root resource. This must be seperated because Django must be # start from inside a thread with database access. self.site = OverlaySite(Resource(), logFormatter=reducedWebLogFormatter, timeout=None) self.site.requestFactory = CleanPathRequest # `endpoint` is set in `privilegedStartService`, at this point the # `endpoint` is None. super().__init__(None, self.site) self.websocket = WebSocketFactory(listener) self.threadpool = ThreadPoolLimiter(reactor.threadpoolForDatabase, concurrency.webapp) self.status_worker = status_worker
def make_protocol(self, patch_authenticate=True, transport_uri=""): listener = FakePostgresListenerService() factory = WebSocketFactory(listener) self.patch(factory, "registerRPCEvents") self.patch(factory, "unregisterRPCEvents") factory.startFactory() self.addCleanup(factory.stopFactory) protocol = factory.buildProtocol(None) protocol.transport = MagicMock() protocol.transport.cookies = b"" protocol.transport.uri = transport_uri protocol.transport.host = random.choice([ maastesting_factory.make_ipv4_address() + ":%d" % maastesting_factory.pick_port(), "[" + maastesting_factory.make_ipv6_address() + "]:%d" % maastesting_factory.pick_port(), ]) protocol.request = HttpRequest() if patch_authenticate: self.patch(protocol, "authenticate") return protocol, factory