How can I fake a twisted.web.client.Response object for testing purposes?

244 Views Asked by At

I'm trying to write a test for a Protocol that expects a t.w.c.Response object. I thought it would be as easy as instantiating the object with the appropriate version string, response code, phrase and t.w.c.Header instance, but I'm not sure how to handle the last parameter, _transport.

As far as I can tell, _transport is where the response body will come from when Response.deliverBody is called. Since this is precisely what my protocol must be able to handle, it seems as though I will need to fake a _transport as well (assuming my guess as to the role of this parameter is correct).

My questions are as follows:

  1. What is the purpose of the _transport parameter? Is my understanding correct?
  2. Assuming my intuition is correct, how can I fake a _transport such that I can call deliverBody on my dummy Response?
  3. Is there perhaps a simpler way to get a dummy Response object?

Any additional tips and advice are welcome!

0

There are 0 best solutions below