Today’s big achievement was an LDAP mock object, similar to the SMTP mock object found in
paste.fixture. I was refactoring the sign in and sign out code of an in-house application that uses LDAP as an authentication store, and I needed to test that the logic of the controllers was correct. So, referring back to Paste’s lovely
fixture module, I came up with the following:
A bit hackish, yes, but I’m not trying to reimplement LDAP here, I just want to trap the calls I use. Obviously a little bit of work is needed to, say, disallow the bind, or throw an exception, but these are trivial extensions.
Just as in
Dummy_smtplib, you call the classmethod
install to set it up (i.e. monkeypatch
ldap.initialize) and you get to trap how it behaves.