I have a piece of code that calls Pyramid's render_to_response. I am not quite sure how to test that piece. In my test, the request object that is sent in is a DummyRequest by Pyramid. How can I capture to_be_rendered.
from pyramid.renderers import render_to_response
def custom_adapter(response):
data = {
'message': response.message
}
to_be_rendered = render_to_response(response.renderer, data)
to_be_rendered.status_int = response.status_code
return to_be_rendered
I believe render_to_response should return a response object. You should be able to call custom_adapter directly in your unit test, providing a DummyRequest and make assertions on the Response object returned by your custom_adapter
def test_custom_adapter(self):
dummy = DummyRequest() # not sure of the object here
response = custom_adapter(dummy)
self.assertEqual(response.status, 200)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With