zulip / fakeldap

A fake ldap implementation to be used in unittests.
21 stars 24 forks source link

Returning exceptions #23

Open michaelsteigman opened 3 years ago

michaelsteigman commented 3 years ago

Has consideration been given to allowing tests to pass in an exception to return? E.g.

self.mock_ldap.set_return_value( "simple_bind_s", ("cn=admin,dc=mgb,dc=org", "ldaptest"), ldap.SERVER_DOWN )

timabbott commented 3 years ago

I haven't thought about this (though maybe the original maintainer did -- we have mostly done bug fixes and Python version support updates since adopting the project). I would try to follow the patterns of the Python mock library for this sort of thing; and so I wouldn't conflate a return value (returning an exception object) with raising an exception in the syntax. See https://docs.python.org/3/library/unittest.mock.html ; I think we probably would want to call this side_effect.

Patches that come with tests are welcome!

michaelsteigman commented 3 years ago

Yes, of course. I’ve used that pattern for this type of testing in the past.

Ok, if time allows, I’ll put something together and submit a PR. Thanks!

On Mar 4, 2021, at 7:16 PM, Tim Abbott notifications@github.com wrote:

I haven't thought about this (though maybe the original maintainer did -- we have mostly done bug fixes and Python version support updates since adopting the project). I would try to follow the patterns of the Python mock library for this sort of thing; and so I wouldn't conflate a return value (returning an exception object) with raising an exception in the syntax. See https://docs.python.org/3/library/unittest.mock.html https://docs.python.org/3/library/unittest.mock.html ; I think we probably would want to call this side_effect.

Patches that come with tests are welcome!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/zulip/fakeldap/issues/23#issuecomment-791046686, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAK4Q5D3PCD44NPLHRUQVPLTCAPEVANCNFSM4YUCX55A.