# Path: ldaptor/protocols/ldap/ldapclient.py
# class LDAPClientConnectionLostException(ldaperrors.LDAPException):
# class LDAPStartTLSBusyError(ldaperrors.LDAPOperationsError):
# class LDAPClient(protocol.Protocol):
#     def __str__(self):
#     def __init__(self, onwire, message=None):
#     def __str__(self):
#     def __init__(self):
#     def dataReceived(self, recd):
#     def connectionMade(self):
#     def connectionLost(self, reason=protocol.connectionDone):
#     def _send(self, op):
#     def _cbSend(self, msg, d):
#     def send(self, op):
#     def send_multiResponse(self, op, handler, *args, **kwargs):
#     def send_noResponse(self, op):
#     def unsolicitedNotification(self, msg):
#     def handle(self, msg):
#     def bind(self, dn='', auth=''):
#     def _handle_bind_msg(self, msg):
#     def unbind(self):
#     def _cbStartTLS(self, msg, ctx):
#     def startTLS(self, ctx=None):
#     def _startTLS(self, ctx):
# 
# Path: ldaptor/testutil.py
# def mustRaise(dummy):
# def calltrace():
#     def printfuncnames(frame, event, arg):
#     def __init__(self, proto):
#     def loseConnection(self):
#     def __init__(self, *responses):
#     def send(self, op):
#     def send_multiResponse(self, op, handler, *args, **kwargs):
#     def send_noResponse(self, op):
#     def _response(self):
#     def assertNothingSent(self):
#     def assertSent(self, *shouldBeSent):
#     def connectionMade(self):
#     def connectionLost(self, reason=None):
#     def unbind(self):
# def createServer(proto, *responses, **kw):
#     def createClient(factory):
# class FakeTransport:
# class LDAPClientTestDriver:


from twisted.trial import unittest
from twisted.test import proto_helpers
from twisted.internet import defer
from ldaptor.protocols.ldap import ldapclient
from ldaptor import testutil
"""
Test cases for ldaptor.protocols.ldap.ldapsyntax module.
"""



class SillyMessage(object):
    needs_answer = True
    def __init__(self, value):
        self.value = value
    def __str__(self):
        return self.value

class SillyError(Exception):
    def __str__(self):
        'Exception for test purposes.'

class ConnectionLost(unittest.TestCase):
    def test_simple(self):
        c = ldapclient.LDAPClient()
        c.makeConnection(proto_helpers.StringTransport())
        d1 = c.send(SillyMessage('foo'))
        d2 = c.send(SillyMessage('bar'))
        c.connectionLost(SillyError())

        def eb(fail):
            fail.trap(SillyError)
        d1.addCallbacks(testutil.mustRaise, eb)

# Path: ldaptor/protocols/ldap/ldapclient.py
# class LDAPClientConnectionLostException(ldaperrors.LDAPException):
# class LDAPStartTLSBusyError(ldaperrors.LDAPOperationsError):
# class LDAPClient(protocol.Protocol):
#     def __str__(self):
#     def __init__(self, onwire, message=None):
#     def __str__(self):
#     def __init__(self):
#     def dataReceived(self, recd):
#     def connectionMade(self):
#     def connectionLost(self, reason=protocol.connectionDone):
#     def _send(self, op):
#     def _cbSend(self, msg, d):
#     def send(self, op):
#     def send_multiResponse(self, op, handler, *args, **kwargs):
#     def send_noResponse(self, op):
#     def unsolicitedNotification(self, msg):
#     def handle(self, msg):
#     def bind(self, dn='', auth=''):
#     def _handle_bind_msg(self, msg):
#     def unbind(self):
#     def _cbStartTLS(self, msg, ctx):
#     def startTLS(self, ctx=None):
#     def _startTLS(self, ctx):
# 
# Path: ldaptor/testutil.py
# def mustRaise(dummy):
# def calltrace():
#     def printfuncnames(frame, event, arg):
#     def __init__(self, proto):
#     def loseConnection(self):
#     def __init__(self, *responses):
#     def send(self, op):
#     def send_multiResponse(self, op, handler, *args, **kwargs):
#     def send_noResponse(self, op):
#     def _response(self):
#     def assertNothingSent(self):
#     def assertSent(self, *shouldBeSent):
#     def connectionMade(self):
#     def connectionLost(self, reason=None):
#     def unbind(self):
# def createServer(proto, *responses, **kw):
#     def createClient(factory):
# class FakeTransport:
# class LDAPClientTestDriver:


# Path: ldaptor/test/test_ldapclient.py
from twisted.trial import unittest
from twisted.test import proto_helpers
from twisted.internet import defer
from ldaptor.protocols.ldap import ldapclient
from ldaptor import testutil

"""
Test cases for ldaptor.protocols.ldap.ldapsyntax module.
"""



class SillyMessage(object):
    needs_answer = True
    def __init__(self, value):
        self.value = value
    def __str__(self):
        return self.value

class SillyError(Exception):
    def __str__(self):
        'Exception for test purposes.'

class ConnectionLost(unittest.TestCase):
    def test_simple(self):
        c = ldapclient.LDAPClient()
        c.makeConnection(proto_helpers.StringTransport())
        d1 = c.send(SillyMessage('foo'))
        d2 = c.send(SillyMessage('bar'))
        c.connectionLost(SillyError())

        def eb(fail):
            fail.trap(SillyError)
        d1.addCallbacks(testutil.mustRaise, eb)

        d2.addCallbacks(testutil.mustRaise, eb)