Пример #1
0
    def test_failedBuildProtocol(self):
        """
        An exception raised in C{buildProtocol} of our wrappedFactory
        results in our C{onConnection} errback being fired.
        """

        class BogusFactory(ClientFactory):
            """
            A one off factory whose C{buildProtocol} raises an C{Exception}.
            """

            def buildProtocol(self, addr):
                raise ValueError("My protocol is poorly defined.")


        wf = endpoints._WrappingFactory(BogusFactory())

        wf.buildProtocol(None)

        d = self.assertFailure(wf._onConnection, ValueError)
        d.addCallback(lambda e: self.assertEqual(
                e.args,
                ("My protocol is poorly defined.",)))

        return d
Пример #2
0
 def test_logPrefixPassthrough(self):
     """
     If the wrapped protocol provides L{ILoggingContext}, whatever is
     returned from the wrapped C{logPrefix} method is returned from
     L{_WrappingProtocol.logPrefix}.
     """
     wf = endpoints._WrappingFactory(TestFactory())
     wp = wf.buildProtocol(None)
     self.assertEqual(wp.logPrefix(), "A Test Protocol")
Пример #3
0
 def test_logPrefixPassthrough(self):
     """
     If the wrapped protocol provides L{ILoggingContext}, whatever is
     returned from the wrapped C{logPrefix} method is returned from
     L{_WrappingProtocol.logPrefix}.
     """
     wf = endpoints._WrappingFactory(TestFactory())
     wp = wf.buildProtocol(None)
     self.assertEqual(wp.logPrefix(), "A Test Protocol")
Пример #4
0
 def test_doStart(self):
     """
     L{_WrappingFactory.doStart} passes through to the wrapped factory's
     C{doStart} method, allowing application-specific setup and logging.
     """
     factory = ClientFactory()
     wf = endpoints._WrappingFactory(factory)
     wf.doStart()
     self.assertEqual(1, factory.numPorts)
Пример #5
0
 def test_doStart(self):
     """
     L{_WrappingFactory.doStart} passes through to the wrapped factory's
     C{doStart} method, allowing application-specific setup and logging.
     """
     factory = ClientFactory()
     wf = endpoints._WrappingFactory(factory)
     wf.doStart()
     self.assertEqual(1, factory.numPorts)
Пример #6
0
 def connect(self, protocolFactory):
     """
     Implement L{IStreamClientEndpoint.connect} to connect via a
     UNIX Socket
     """
     try:
         wf = _WrappingFactory(protocolFactory)
         self._reactor.connectUNIX(self._path, wf, timeout=self._timeout, checkPID=self._checkPID)
         return wf._onConnection
     except:
         return defer.fail()
Пример #7
0
 def test_logPrefixDefault(self):
     """
     If the wrapped protocol does not provide L{ILoggingContext}, the wrapped
     protocol's class name is returned from L{_WrappingProtocol.logPrefix}.
     """
     class NoProtocol(object):
         pass
     factory = TestFactory()
     factory.protocol = NoProtocol
     wf = endpoints._WrappingFactory(factory)
     wp = wf.buildProtocol(None)
     self.assertEqual(wp.logPrefix(), "NoProtocol")
Пример #8
0
    def test_wrappedProtocolConnectionLost(self):
        """
        Our wrappedProtocol's connectionLost method is called when
        L{_WrappingProtocol.connectionLost} is called.
        """
        tf = TestFactory()
        wf = endpoints._WrappingFactory(tf)
        p = wf.buildProtocol(None)

        p.connectionLost("fail")

        self.assertEqual(p._wrappedProtocol.connectionsLost, ["fail"])
Пример #9
0
    def test_wrappedProtocolConnectionLost(self):
        """
        Our wrappedProtocol's connectionLost method is called when
        L{_WrappingProtocol.connectionLost} is called.
        """
        tf = TestFactory()
        wf = endpoints._WrappingFactory(tf)
        p = wf.buildProtocol(None)

        p.connectionLost("fail")

        self.assertEqual(p._wrappedProtocol.connectionsLost, ["fail"])
Пример #10
0
    def test_logPrefixDefault(self):
        """
        If the wrapped protocol does not provide L{ILoggingContext}, the wrapped
        protocol's class name is returned from L{_WrappingProtocol.logPrefix}.
        """
        class NoProtocol(object):
            pass

        factory = TestFactory()
        factory.protocol = NoProtocol
        wf = endpoints._WrappingFactory(factory)
        wp = wf.buildProtocol(None)
        self.assertEqual(wp.logPrefix(), "NoProtocol")
Пример #11
0
    def test_wrappedProtocolDataReceived(self):
        """
        The wrapped C{Protocol}'s C{dataReceived} will get called when our
        C{_WrappingProtocol}'s C{dataReceived} gets called.
        """
        wf = endpoints._WrappingFactory(TestFactory())
        p = wf.buildProtocol(None)
        p.makeConnection(None)

        p.dataReceived(b'foo')
        self.assertEqual(p._wrappedProtocol.data, [b'foo'])

        p.dataReceived(b'bar')
        self.assertEqual(p._wrappedProtocol.data, [b'foo', b'bar'])
Пример #12
0
 def connect(self, protocolFactory):
     """
     Implement L{IStreamClientEndpoint.connect} to connect via a
     UNIX Socket
     """
     try:
         wf = _WrappingFactory(protocolFactory)
         self._reactor.connectUNIX(
             self._path, wf,
             timeout=self._timeout,
             checkPID=self._checkPID)
         return wf._onConnection
     except:
         return defer.fail()
Пример #13
0
    def test_wrappedProtocolDataReceived(self):
        """
        The wrapped C{Protocol}'s C{dataReceived} will get called when our
        C{_WrappingProtocol}'s C{dataReceived} gets called.
        """
        wf = endpoints._WrappingFactory(TestFactory())
        p = wf.buildProtocol(None)
        p.makeConnection(None)

        p.dataReceived(b'foo')
        self.assertEqual(p._wrappedProtocol.data, [b'foo'])

        p.dataReceived(b'bar')
        self.assertEqual(p._wrappedProtocol.data, [b'foo', b'bar'])
Пример #14
0
    def test_wrappedProtocolTransport(self):
        """
        Our transport is properly hooked up to the wrappedProtocol when a
        connection is made.
        """
        wf = endpoints._WrappingFactory(TestFactory())
        p = wf.buildProtocol(None)

        dummyTransport = object()

        p.makeConnection(dummyTransport)

        self.assertEqual(p.transport, dummyTransport)

        self.assertEqual(p._wrappedProtocol.transport, dummyTransport)
Пример #15
0
    def test_wrappedProtocolTransport(self):
        """
        Our transport is properly hooked up to the wrappedProtocol when a
        connection is made.
        """
        wf = endpoints._WrappingFactory(TestFactory())
        p = wf.buildProtocol(None)

        dummyTransport = object()

        p.makeConnection(dummyTransport)

        self.assertEqual(p.transport, dummyTransport)

        self.assertEqual(p._wrappedProtocol.transport, dummyTransport)
Пример #16
0
 def connect(self, protocolFactory):
     """
     Implement L{IStreamClientEndpoint.connect} to connect with SSL over
     TCP.
     """
     try:
         wf = _WrappingFactory(protocolFactory)
         self._reactor.connectSSL(
             self._host,
             self._port,
             wf,
             self._sslContextFactory,
             timeout=self._timeout,
             bindAddress=self._bindAddress,
         )
         return wf._onConnection
     except:
         return defer.fail()
Пример #17
0
    def test_clientConnectionFailed(self):
        """
        Calls to L{_WrappingFactory.clientConnectionLost} should errback the
        L{_WrappingFactory._onConnection} L{Deferred}
        """
        wf = endpoints._WrappingFactory(TestFactory())
        expectedFailure = Failure(error.ConnectError(string="fail"))

        wf.clientConnectionFailed(None, expectedFailure)

        errors = []

        def gotError(f):
            errors.append(f)

        wf._onConnection.addErrback(gotError)

        self.assertEqual(errors, [expectedFailure])
Пример #18
0
    def test_clientConnectionFailed(self):
        """
        Calls to L{_WrappingFactory.clientConnectionLost} should errback the
        L{_WrappingFactory._onConnection} L{Deferred}
        """
        wf = endpoints._WrappingFactory(TestFactory())
        expectedFailure = Failure(error.ConnectError(string="fail"))

        wf.clientConnectionFailed(
            None,
            expectedFailure)

        errors = []
        def gotError(f):
            errors.append(f)

        wf._onConnection.addErrback(gotError)

        self.assertEqual(errors, [expectedFailure])
Пример #19
0
    def test_failedBuildProtocol(self):
        """
        An exception raised in C{buildProtocol} of our wrappedFactory
        results in our C{onConnection} errback being fired.
        """
        class BogusFactory(ClientFactory):
            """
            A one off factory whose C{buildProtocol} raises an C{Exception}.
            """
            def buildProtocol(self, addr):
                raise ValueError("My protocol is poorly defined.")

        wf = endpoints._WrappingFactory(BogusFactory())

        wf.buildProtocol(None)

        d = self.assertFailure(wf._onConnection, ValueError)
        d.addCallback(lambda e: self.assertEqual(e.args, (
            "My protocol is poorly defined.", )))

        return d