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 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