def test_tlsAfterStartTLS(self): """ The C{TLS} attribute of a L{Connection} instance is C{True} after L{Connection.startTLS} is called. """ skt = FakeSocket("") protocol = FakeProtocol() conn = Connection(skt, protocol, reactor=_FakeFDSetReactor()) conn._tlsClientDefault = True conn.startTLS(ClientContextFactory(), True) self.assertTrue(conn.TLS)
def test_doReadWarningIsRaised(self): """ When an L{IProtocol} implementation that returns a value from its C{dataReceived} method, a deprecated warning is emitted. """ skt = FakeSocket("someData") protocol = FakeProtocol() conn = Connection(skt, protocol) conn.doRead() warnings = self.flushWarnings([FakeProtocol.dataReceived]) self.assertEquals(warnings[0]['category'], DeprecationWarning) self.assertEquals( warnings[0]["message"], "Returning a value other than None from " "twisted.internet.test.test_tcp.FakeProtocol.dataReceived " "is deprecated since Twisted 11.0.0.") self.assertEquals(len(warnings), 1)
def test_doReadWarningIsRaised(self): """ When an L{IProtocol} implementation that returns a value from its C{dataReceived} method, a deprecated warning is emitted. """ skt = FakeSocket("someData") protocol = FakeProtocol() conn = Connection(skt, protocol) conn.doRead() warnings = self.flushWarnings([FakeProtocol.dataReceived]) self.assertEqual(warnings[0]['category'], DeprecationWarning) self.assertEqual( warnings[0]["message"], "Returning a value other than None from " "twisted.internet.test.test_tcp.FakeProtocol.dataReceived " "is deprecated since Twisted 11.0.0.") self.assertEqual(len(warnings), 1)
def __init__(self, sock, protocol, addr, additionalData): Connection.__init__(self, sock, protocol) self.client = addr # Inform the protocol we've made a connection. protocol.makeConnection(self) # Now, we want to feed in the extra data BEFORE the reactor reads # anything additional from the socket. However, if we call this in # the other order, and the socket gets closed (or passed to something # non-twisted) after just the initial chunk, we'll be calling # startReading() on something we've already stopped reading. That won't # work too well... Fortunately, the reactor runs in this thread, so # merely adding it (with startReading()) can't cause a read to happen # immediately. self.startReading() self.connected = 1 protocol.dataReceived(additionalData)
def test_getWriters(self): """ Check that L{interfaces.IReactorFDSet.getWriters} reflects the actions made with L{interfaces.IReactorFDSet.addWriter} and L{interfaces.IReactorFDSet.removeWriter}. """ s = socket.socket() self.addCleanup(s.close) c = Connection(s, protocol.Protocol()) self.assertNotIn(c, reactor.getWriters()) reactor.addWriter(c) self.assertIn(c, reactor.getWriters()) reactor.removeWriter(c) self.assertNotIn(c, reactor.getWriters())