Using dataflake.fakeldap
The class ldap.fakeldap.FakeLDAPConnection
can be used
as a replacement for the various connection-modeling classes
in the module ldap.ldapobject
.
If the connection class used by your code can be provided at runtime, simply use the replacement:
from dataflake.fakeldap import FakeLDAPConnection
class MyClass(object):
def __init__(self, connection_class, uri):
self.connection = connection_class(uri)
...
my_object = MyClass(connection_class=FakeLDAPConnection)
If your code imports one of the different LDAP connection classes
inside the ldap.ldapobject
module directly, you can simply
patch in the ldap.fakeldap.FakeLDAPConnection
class:
class MyTests(unittest.TestCase):
def setUp(self):
from dataflake.fakeldap import FakeLDAPConnection
from ldap import ldapobject
self.old_connection_class = ldapobject.LDAPObject
ldapobject.LDAPObject = FakeLDAPConnection
def tearDown(self):
from ldap import ldapobject
ldapobject.LDAPObject = self.old_connection_class
def test_something(self):
...