'If :py:obj:`Connection.set_session` is passed a :py:class:`Session`
instance associated with a context using a different SSL method than the
:py:obj:`Connection` is using, a :py:class:`OpenSSL.SSL.Error` is
raised.'

def test_set_session_wrong_method(self):

    key = load_privatekey(FILETYPE_PEM, server_key_pem)
    cert = load_certificate(FILETYPE_PEM, server_cert_pem)
    ctx = Context(TLSv1_METHOD)
    ctx.use_privatekey(key)
    ctx.use_certificate(cert)
    ctx.set_session_id('unity-test')
    def makeServer(socket):
        server = Connection(ctx, socket)
        server.set_accept_state()
        return server
    (originalServer, originalClient) = self._loopback(serverFactory=makeServer)
    originalSession = originalClient.get_session()
    def makeClient(socket):
        client = Connection(Context(SSLv3_METHOD), socket)
        client.set_connect_state()
        client.set_session(originalSession)
        return client
    self.assertRaises(Error, self._loopback, clientFactory=makeClient, serverFactory=makeServer)
