def test_doubleSTARTTLS(self):
        """
        A server that receives a second C{STARTTLS} sends a C{NO}
        response.
        """

        class DoubleSTARTTLSClient(SimpleClient):

            def startTLS(self):
                if not self.startedTLS:
                    return SimpleClient.startTLS(self)

                return self.sendCommand(imap4.Command(b"STARTTLS"))

        self.client = DoubleSTARTTLSClient(self.connected,
                                           contextFactory=self.clientCTX)

        disconnected = self.startTLSAndAssertSession()

        self.connected.addCallback(strip(self.client.startTLS))
        self.connected.addErrback(self.assertClientFailureMessage, b"TLS already negotiated")

        self.connected.addCallback(self._cbStopClient)
        self.connected.addErrback(self._ebGeneral)

        return disconnected

        A server that receives a second C{STARTTLS} sends a C{NO}
        response.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/mail/test/test_imap.py