'When a user cancels L{twisted.mail.smtp.sendmail} after the connection
is made, the connection is closed by
L{twisted.internet.interfaces.ITransport.abortConnection}.'

def test_cancelAfterConnectionMade(self):

    reactor = MemoryReactor()
    transport = AbortableStringTransport()
    d = smtp.sendmail('localhost', 'source@address', 'recipient@address', 'message', reactor=reactor)
    factory = reactor.tcpClients[0][2]
    p = factory.buildProtocol(None)
    p.makeConnection(transport)
    d.cancel()
    self.assertEqual(transport.aborting, True)
    self.assertEqual(transport.disconnecting, True)
    failure = self.failureResultOf(d)
    failure.trap(defer.CancelledError)
