Hi folks, need some advice here.

("AcceleratedHTTPCacheManager doesn't PURGE correctly for virtual
hosts") has been assigned to me like forever, and I've determined
to not let another year go by with this one unfixed ;-)

I'd like to apply the patch and commit, once I'm sure it works
correctly, but - drumroll - AcceleratedHTTPCacheManager has no test
suite at all.  Which means, as frequently happens with Zope 2, I have to
go through the pain of setting up a test suite for the current behavior
before I go changing anything.

The fun thing about this is that AcceleratedHTTPCache uses httplib to
send purge notifications. I don't fancy launching a dummy server of some
sort. So, I'm asking for advice: How in general does one go about
setting up a unit test for network client code? 

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:

class AcceleratedHTTPCache (Cache):
    client_class = httplib.HTTPConnection
    def ZCache_invalidate(self, ob):
            h = self.client_class(host)

Then I can just do something like this during afterSetUp():

    cache = AcceleratedHTTPCache()
    cache.client_class = MockHTTPConnection

Any better ideas?



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

Reply via email to