On 3 Dec 2005, at 15:57, Paul Winkler wrote:
One thought that occurs to me is to replace httplib.HTTPConnection with
a mock object of some sort that allows easy verification of its input.
So we assume that httplib works, as a proper unit test should I think.
How to do this? One idea is to monkeypatch httplib during the course of the test case, and replace and then when the test finishes, restore the
old httplib.HTTPConnection.  But this idea smells pretty bad to me.
Another thought: Maybe before doing anything else, I should make the
client class used by AcceleratedHTTPCache configurable, so I can more
easily get a mock in there.  Something like:

I like the secondary route, but I'm not sure the production code should contain "testing only" turds. :)

I have done the first route on many occasions, mostly with the LDAPUserFolder where I actually replace a class in the python-ldap module with one that fakes out a LDAP connection object so I can operate on it:

# Do some namespace manipulation to make use of FakeLDAP
from Products.LDAPUserFolder.tests import FakeLDAP
sys.modules['ldap'] = FakeLDAP

This could also be done in setUp/tearDown, which I should really do because this code does not clean up after itself. If you happened to run other code after running the test and with the same running interpreter that just happens to use the python-ldap module you'd be in bad shape ;)


Zope-Dev maillist  -  Zope-Dev@zope.org
**  No cross posts or HTML encoding!  **
(Related lists - http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope )

Reply via email to